PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Confirm reservation via confirmation link in email

  1. This is the scenario: A form to make reservations for an event. After submitting the form, the client receives an email with a confirmation link. This is to avoid somebody makes an unwanted reservation for somebody else. If the client clicks the confirmation link in his email he is routed to a page where his reservation is confirmed. The entry of this client in the entries table of the form is updated. So in the cms the administrator can see in the entries table which clients confirmed their reservation and which clients didn't.

    Is this possible with Gravity Forms?

    Posted 11 years ago on Friday April 26, 2013 | Permalink
  2. David Peralty

    It is possible, but not built-in. You would have to custom code the URL for approvals and the tool to update the entries when they arrive on the site.

    Posted 11 years ago on Friday April 26, 2013 | Permalink
  3. Thanks David. Could you point me in the right directions how to do that?
    Here is what I can think of:

    As for the url for approval: That would require a random and dynamically generated code that is stored in the entry, perhaps in a hidden field. Is there a way to let GF generate a random code? Perhaps by dynamically populating the hidden field via a hook that could be programmed to generate a random string? How and where would I place such a hook?

    As for updating the entry: I suppose I could add another hidden field 'confirmed' with a default value of 0 (false). How could I alter this field to 1 (true) programmatically from another page outside GF, using the unique string generated in the previous step to identify the right entry? Would this just be a matter of updating the database entry directly via a query or is there a hook for this?

    tia,
    Erik

    Posted 11 years ago on Friday April 26, 2013 | Permalink
  4. David Peralty

    You are totally on the right track, and outlining exactly what I was thinking when you asked the question.

    I would use gform_pre_submission as the hook to create the random key (maybe a md5 hash of two combined field values) and place it in the hidden field.

    For the second part, you can have a hidden field with a default value of 0. The user would click on the link and go to your specially created Verify page. It would just use a mysql command to search for the key, and if it found it, then update the entry to have a 1 instead of a 0.

    Posted 11 years ago on Friday April 26, 2013 | Permalink
  5. Hi David,
    Thanks for pointing me to the right hook. I've got this working. Here's the code I put in functions.php:

    add_action("gform_pre_submission", "random_value_in_hidden_field");
    function random_value_in_hidden_field($form){
        $_POST["input_3"] = md5(rand(0,time()));
    }

    This I put in the notification email:
    <a href="http:/mydomain.com/confirmation-page?usercode={Usercode:3}">Confirm your registration</a>
    And this went in the confirmation page's php template:

    <?php
    if (empty($_GET)){}
    else {
    	if (empty($_GET["usercode"])) {}
    	else {
    		$uc = $_GET["usercode"];
    		$sql = "SELECT * FROM <code>wp_rg_lead_detail</code> WHERE <code>value</code> = '$uc'";
    		$myrows = $wpdb->get_row( $sql, ARRAY_A );
    		if (empty($myrows)) {}
    		else {
    			$lead_id = $myrows["lead_id"];
    			$wpdb->update( 'wp_rg_lead_detail', array('value' => 1) , array( 'lead_id' => $lead_id, 'field_number' => 4) );
    		}
    	}
    }
    ?>

    Now a final cherry on the cake would be a second email to the client to confirm the confirmation of his registration was succesfully processed. Any chance there would be a way to do that with GF? Or should I just send an oldskool email from the same confirmation page by php?

    Posted 11 years ago on Friday April 26, 2013 | Permalink