WordPress.org

Forums

Contact Form DB
[resolved] [Plugin: Contact Form 7 to Database Extension] Comparing data before submission - Custom error handl (9 posts)

  1. frinkky
    Member
    Posted 2 years ago #

    I need to compare the email address of a submitted form against a separate database of customers. If the email address is found, the form can be submitted. If not, an error should be displayed.

    I've wrapped the contents of saveFormData() (CF7DBPlugin.php) with something similar to:

    //DB Info & Connect
    //Escape fields
    
    $sql="SELECT * FROM emails WHERE emailaddr = '".$emailaddr."'";
    $result = mysql_query($sql);
    $count = mysql_num_rows($result);
    
    if($count == 0){
    // Error
    }
    else {
        try{
            // Original code

    It works fine except nothing I put in the error region seems to work. Can you explain how to hook into the error system to display an error message?

    Thanks in advance.

    http://wordpress.org/extend/plugins/contact-form-7-to-database-extension/

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

  2. Nitesh
    Member
    Posted 2 years ago #

    I am also looking a solution for the same problem.
    For moderator -
    In the SaveFormData() present in (CF7DBPlugin.php), we are adding a validator code that checks if the data needs to be saved in Db or not.

    public function saveFormData($cf7) {
    WRITING THE CUSTOM HANDLER HERE TO CHECK IF DB INSERTION IS REQUIRED OR NOT. NEED TO KNOW HOW TO DISPLAY CUSTOM MESSAGES TO USER HERE.
    try
    {
    //ORIGINAL CODE FROM THE PLUGIN
    }
    }
  3. frinkky
    Member
    Posted 2 years ago #

    Hi,

    I moved my code to classes.php of Contact Form 7 directly in the submit() function.

    I generate an error with this elseif:

    elseif (($_POST['isreq'] == 'req') && ($count == 0)) {
    	$result['message'] = $this->message( 'email-mismatch' );
    }

    ($_POST['isreq'] is just a hidden field used to determine this is a form I want to use this validation on).

    I then added a custom error message under wpcf7_messages() in functions.php:

    'email-mismatch' => array(
    	'description' => __( "The email supplied does not match the account email", 'wpcf7' ),
    	'default' => __( 'Failed to submit your competition entry. Please ensure you are using your account email. If necessary, you can log in to update your email <a href="" title="">here</a>.', 'wpcf7' )
    		)
  4. Nitesh
    Member
    Posted 2 years ago #

    Doing the same with my plugin too.. Btw, Thanks for sharing!!

  5. Elnz
    Member
    Posted 2 years ago #

    Hi,

    i need help here. If i understand i need to add a custom handrel to check if DB insertion is required. I must add this in function saveFormData($cf7). If db insertion isn't required i display a message by function submit.

    Ok, now i put the message in submit function, and i write my validation email. My problem is, how i can wrapp the email sendend by user??.

  6. Elnz
    Member
    Posted 2 years ago #

    Ok done. I put my code in saveFormData($cf7) of CF7DBPlugin.php and i catch a new exception.

    Now i need to send a new error message via POST. I think i need to do it in submit function (classes.php). But i dont understand how. Can You help me plz?^^

  7. suite8
    Member
    Posted 2 years ago #

    @frinkky

    Can you tell me exactley how I need to edit classes.php and functions.php to achieve what you achieved. I'm no php expert so can you please post a pastebin link?

    Thanks

  8. suite8
    Member
    Posted 2 years ago #

    I really need some help with this guys. Anyone who could help me to where my form will put up an error message if an e-mail address is ALREADY in the database? Anyone?

  9. Michael Simpson
    Member
    Plugin Author

    Posted 2 years ago #

    The approach I would take is to try to add a CF7 custom validation (this post may help) and in the validation I would put code to query for the presumed original submission (see this post).

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form DB
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.