0

I am using WordPress and Gravity Forms plugin and I am trying to pass a parameter from a third party provider to a Gravity Form with Dynamic Population from another page, using the below code

<form method="post" name="goToForm" action="http://www.example.com/?page_id=123">
    <input type="hidden" name="param" value="Hello">
    <input type="submit" name="fromSubmit" value="Submit">
</form>

Note that the above http://www.example.com/?page_id=123 is the Gravity Form URL.

the closest solution I found is using the HOOK method, but still I want to know how can I call the custom function that is created in functions.php using the HOOK approach from post and pass the parameter.

Any suggestions will be appreciated

1 Answer 1

2

If I'm understanding you correctly you want to pass the parameters on the form url?

You can accomplish this in 2 ways:

URL: http://www.example.com/?page_id=123

  1. You can add a hidden field in the form. In the advanced section of the field, select Allow field to be populated dynamically and add the parameter name. So example I want to get the page_id:

enter image description here

After saving your form, inspect the hidden field and you should see it's value as 123

  1. You can add a hook function:

    add_filter('gform_field_value_page_id', 'my_custom_population_function'); function my_custom_population_function($value){ return $value'; //or do what ever you want with it }

If you want to add the page title or id automatically to the form:

  1. Add a hidden field, in the advanced section of the field, add this {embed_post:ID} (Post ID) to the default value. OR

  2. Add a hidden field, in the advanced section of the field, add this {embed_post:post_title} (Post Title) to the default value.

Edit

The user is looking for http://www.gravityhelp.com/documentation/page/Gform_after_submission

You can get your fields/parameters from your form and then save it to your database, update a Wordpress page/post or send it to a third party service provider.

I'm not too sure what user would like to do with the parameter, so I'll show an example of sending it to a third party provider:

  • We want our entry field numbers so we can get the correct fields:

    /* Getting correct field numbers */
    
    
    add_action("gform_after_submission", "post_to_third_party", 10, 2);
    
    function post_to_third_party($entry, $form){
        // Lets get the IDs of the relevant fields and prepare an email message
        $message = print_r($entry, true);
        // In case any of our lines are larger than 70 characters, we should use wordwrap()
        $message = wordwrap($message, 70);
        // Send
        mail('[email protected]', 'Getting the Gravity Form Field IDs', $message);
    } 
    

You should get something like this in your mail:

Array
    (
        [id] => 64
        [form_id] => 5
        [date_created] => 2014-07-02 13:27:00
        [is_starred] => 0
        [is_read] => 0
        [ip] => ::1
        [source_url] => http://localhost/
        [post_id] =>
        [currency] => USD
        [payment_status] =>
        [payment_date] =>
        [transaction_id] =>
        [payment_amount] =>
        [payment_method] =>
        [is_fulfilled] =>
        [created_by] => 1
        [transaction_type] =>
        [user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3)
    AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153
    Safari/537.36
        [status] => active
        [1] => Name
        [4] => Parameter
    )

Where [1] => Name is a Name field and I entered Name for testing and [4] => Parameter is the parameter field with a default value of Parameter.

  • After we have our correct field numbers, we can then submit it to the third party provider, I'm using curl in this example:

    /* Submitting to thirdparty.com */
    
    add_action("gform_after_submission", "post_to_third_party", 10, 2);
    
    function post_to_third_party($entry, $form){
    
    
    //Submitting to thirdparty.com using curl
    function post_to_url($url, $data) {
         $fields = '';
         foreach($data as $key => $value) {
         $fields .= $key . '=' . $value . '&';
         }
         rtrim($fields, '&');
         $post = curl_init();
         curl_setopt($post, CURLOPT_URL, $url);
         curl_setopt($post, CURLOPT_POST, count($data));
         curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
         curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($post, CURLOPT_HEADER, 1); //if you want headers
         curl_setopt($post, CURLOPT_HEADER, "Content-Type:application/xml");
         $result = curl_exec($post); 
    
         //If there's an error
    
         if($result === false)
            {
                echo "Error Number:".curl_errno($ch)."<br>";
                echo "Error String:".curl_error($ch);
         }
    
         curl_close($post);
    }
    
    if($form["id"] == 1){//Form ID
        //Lets get the fields to match submission to thirdparty.com
        $data = array(
             "FirstName" =>     $entry["1"],
             "ParameterName" =>     $entry["4"]
        );
    
            post_to_url("http://thirdparty.com", $data);
    }
    
    }

If you want the hook to work for a specific form gform_after_submission_1 will work for form id 1 only.

Sign up to request clarification or add additional context in comments.

5 Comments

many thanks for your help, I already created the hidden field and set the parameter, but I want to send the parameter and call this page (where the gravity form exist) from another page, so I though of using html form method as I explained above. please note that the extension of the URL /?page_id=123 is a WordPress generated and its the reference to the target page not the parameter. Any Suggestions will be appreciated
Oh ok I see, there's a way of doing that. I used page_id as an example. I'll edit my answer!
@user2079954 please see my edit. I dont know what you want to do with the parameter, but the gform_after_submission hook will help you get the value
thanks again for your support, please be informed that I mean to pass the parameter from any other third party provider to gravity form, and for that I tried using the html form to call the gravity form and submit the parameter
@user2079954 I dont think there is any hook to auto submit the gravity form with the parameter from a third party provider. It looks like you want to save the info and it's not possible with Gravity forms unless you do some hard coding on it. I highly suggest writing out a script in php to store the info and save it to your database and then add a Wordpress backend page for viewing the entries stored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.