• Hi There,

    Was just wondering, if its possible to use your form in the following manner:

    1st, we take a form and get the user input.
    2nd, we compare the user input with data from a specific column in the database.
    3rd, if data matches or exist, redirect user to a specific page on wordpress site.

    Would appreciate if you can assist on this. Thanks !

    Regards,
    Wen Jun.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello @wjyeshealth

    You can use wpcf7_mail_sent hook.

    add_action('wpcf7_mail_sent', 'compare_values', 10, 1);
    function compare_values($contact_form) {
        if ( 'Replace_With_FormId' == $contact_form->id() ) {
    	$submission = WPCF7_Submission::get_instance();
    	if ( $submission ) {
    	    $formdata = $submission->get_posted_data(); //Form post data.
    
    	    $email = $formdata['your-email']; //use this to compare values from database.
    	}
        }    
    }
    
    Thread Starter wjyeshealth

    (@wjyeshealth)

    Hi @jainilnagar,

    Thanks for the reply ! However, from the following action hook, I dont see anyway that the comparison and redirection can take place from here, rather the comparison is done in a manual way once I get the response via email.

    Do let me know if the provided action hook takes affect in another way if i had described this wrongly. Thanks.

    Regards,
    Wen Jun.

    Hello @wjyeshealth

    This hook runs after the successful form submission and mail sent. In the $formdata you will get the data submitted on the form.

    You can use that to compare the data fetched from the database. Based on the comparison you can redirect the user to a specific page using code.

    Thread Starter wjyeshealth

    (@wjyeshealth)

    Hi @jainilnagar ,

    Great thanks for the info ! Just curious is it valid to put my database query to read data, together with this action hook?

    Also is it possible to disable email sending on a particular form id everytime a user submits it ?

    Regards,
    Wen Jun.

    Hello @wjyeshealth

    Query:
    You can Worpdress query here to fetch the data.

    Disable Email:
    You can use skip_mail: on to disable mail sending on a particular form in the additional setting area. Check here.

    Thread Starter wjyeshealth

    (@wjyeshealth)

    Hi @jainilnagar,

    Is there any way i can output my user input from the form, so that i know that there is data being inputted correctly into the form ? This is part of my validation process before i compare the data.

    Is there another action hook we could add in here for this ?

    I tried to submit the user input via email earlier, but did not receive the email to validate the data.

    As always thanks for your help ??

    Regards,
    Wen Jun.

    Hello @wjyeshealth

    If you have added skip_mail: on in the form setting area then it will not send any emails.

    Regarding printing post values, you can print them using print_r($formdata) but you must have knowledge on how to use the network tab in the browser console to check the output.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Comparing User input and redirecting’ is closed to new replies.