Send Form to a external url and get a key to submit another form with the key [RESOLVED]

Hi Team,

I am trying to send a form data to external url using Gravity form. After the form is submitted it will generate a report id once I get that report id I want to submit another form with that report id after that I will get a pdf which I want to display on a page.

This is what I could get to so far it level one now just trying to send data first:

Option 1: Gives me a error

add_action(“gform_post_submission”, “post_to_rentfax”, 10, 2);

function post_to_rentfax($entry, $form){
if($form[“id”] != 12) //NOTE: replace number with your form id
return;
?>



<input type=“text” name=“address” value="<?php echo $entry["4.1"] ?>" />
<input type=“text” name=“city” value="<?php echo $entry["4.3"] ?>" />
<input type=“text” name=“state” value="<?php echo $entry["4.4"] ?>" />
<input type=“text” name=“zip” value="<?php echo $entry["4.5"] ?>" />
<input type=“select” name=“propertyType” value="<?php echo $entry["10"] ?>" />
<input type=“select” name=“bedrooms” value="<?php echo $entry["15"] ?>" />
<input type=“select” name=“bathrooms” value="<?php echo $entry["14"] ?>" />
<input type=“select” name=“squareFeet” value="<?php echo $entry["17"] ?>" />

    </form>
    <script type="text/javascript">
        document.getElementById("form_to_rentfax").submit();
		alert("form submitted");
    </script>
<?php

}

When I use the code above it gives me this error: Uncaught DOMException: Blocked a frame with origin “Domainurl” from accessing a cross-origin frame.

Option 2: But doesn’t submit the data neither show any error.
add_action( ‘gform_after_submission_12’, ‘post_to_third_party’, 10, 2 );
function post_to_third_party( $entry, $form ) {
$post_url = ‘https://my.rentfaxpro.com/integration/report’;
$body = array(
‘reportCode’ => ‘RENT-REPORT’,
‘address’ => rgar( $entry, ‘4.1’ ),
‘city’ => rgar( $entry, ‘4.3’ ),
‘state’ => rgar( $entry, ‘4.4’ ),
‘zip’ => rgar( $entry, ‘4.5’ ),
‘propertyType’ => rgar( $entry, ‘10’ ),
‘bedrooms’ => rgar( $entry, ‘15’ ),
‘bathrooms’ => rgar( $entry, ‘14’ ),
‘squareFeet’ => rgar( $entry, ‘17’ ),
);
print_r($body);
GFCommon::log_debug( 'gform_after_submission_12: body => ’ . print_r( $body, true ) );

$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_after_submission_12: response => ' . print_r( $response, true ) );

}

Any help would really be appreciated. Thank you all in advance.

Hi Team,

Forgot to mention I tried using Web-hook add-on as well but it doesn’t work.

Can you share the link to your log file where we can see what is being logged for the $body and $response?

Hi Chris,

Here is the link to the log file :
http://hoffmanpm.wpengine.com/wp-content/uploads/gravity_forms/logs/gravityforms_42cdec2289c4d39004a3a21921b74e6d3af634a2.txt

Let me know if you need anything else.

Regards,
Pallavi

That does not appear in the log file at all. It should be in the log, based in your logging statements:

GFCommon::log_debug( 'gform_after_submission_12: body => ' . print_r( $body, true ) );

GFCommon::log_debug( 'gform_after_submission_12: response => ' . print_r( $response, true ) );

Can you test this again so we can see if those logging statements appear in the log file? Thank you.

Hi Chris,

Thank you so much for your help. I updated the code:

http://hoffmanpm.wpengine.com/wp-content/uploads/gravity_forms/logs/gravityforms_42cdec2289c4d39004a3a21921b74e6d3af634a2.txt

So we see the entries in log file. Deleted old data.

Regards,
Pallavi

Sorry I skipped over this one for a while. Going back to that logging statement, it is in the log file on Dec 21, and the request was successful. This is what was logged:

2018-12-21 12:31:06.660535 - DEBUG --> GFFormDisplay::process_form(): Executing functions hooked to gform_after_submission. 
2018-12-21 12:31:07.666536 - DEBUG --> gform_after_submission_12: body => Array
(
    [apikey] => 6b761a6f-bf77-45a2-a70f-a96de75852a2
    [reportCode] => RENT-REPORT
    [address] => 60 Descanso Drive
    [city] => San Jose
    [state] => California
    [zip] => 95134
    [propertyType] => Single Family Home
    [bedrooms] => 1 Bedroom
    [bathrooms] => 1 Bathroom
    [squareFeet] => 1233
)
 
2018-12-21 12:31:07.666770 - DEBUG --> gform_after_submission_12: response => Array
(
    [headers] => Requests_Utility_CaseInsensitiveDictionary Object
        (
            [data:protected] => Array
                (
                    [date] => Fri, 21 Dec 2018 17:31:07 GMT
                    [server] => Apache-Coyote/1.1
                    [content-length] => 0
                    [set-cookie] => JSESSIONID=136C97886BA89DE9C5621AB1368015CD; Path=/; Secure; HttpOnly
                    [content-type] => text/plain; charset=UTF-8
                )

        )

    [body] => 
    [response] => Array
        (
            [code] => 200
            [message] => OK
        )

    [cookies] => Array
        (
            [0] => WP_Http_Cookie Object
                (
                    [name] => JSESSIONID
                    [value] => 136C97886BA89DE9C5621AB1368015CD
                    [expires] => 
                    [path] => /
                    [domain] => my.rentfaxpro.com
                )

        )

    [filename] => 
    [http_response] => WP_HTTP_Requests_Response Object
        (
            [response:protected] => Requests_Response Object
                (
                    [body] => 
                    [raw] => HTTP/1.1 200 OK
Date: Fri, 21 Dec 2018 17:31:07 GMT
Server: Apache-Coyote/1.1
Content-Length: 0
Set-Cookie: JSESSIONID=136C97886BA89DE9C5621AB1368015CD; Path=/; Secure; HttpOnly
Connection: close
Content-Type: text/plain; charset=UTF-8


                    [headers] => Requests_Response_Headers Object
                        (
                            [data:protected] => Array
                                (
                                    [date] => Array
                                        (
                                            [0] => Fri, 21 Dec 2018 17:31:07 GMT
                                        )

                                    [server] => Array
                                        (
                                            [0] => Apache-Coyote/1.1
                                        )

                                    [content-length] => Array
                                        (
                                            [0] => 0
                                        )

                                    [set-cookie] => Array
                                        (
                                            [0] => JSESSIONID=136C97886BA89DE9C5621AB1368015CD; Path=/; Secure; HttpOnly
                                        )

                                    [content-type] => Array
                                        (
                                            [0] => text/plain; charset=UTF-8
                                        )

                                )

                        )

                    [status_code] => 200
                    [protocol_version] => 1.1
                    [success] => 1
                    [redirects] => 0
                    [url] => https://my.rentfaxpro.com/integration/report
                    [history] => Array
                        (
                        )

                    [cookies] => Requests_Cookie_Jar Object
                        (
                            [cookies:protected] => Array
                                (
                                    [JSESSIONID] => Requests_Cookie Object
                                        (
                                            [name] => JSESSIONID
                                            [value] => 136C97886BA89DE9C5621AB1368015CD
                                            [attributes] => Requests_Utility_CaseInsensitiveDictionary Object
                                                (
                                                    [data:protected] => Array
                                                        (
                                                            [path] => /
                                                            [secure] => 1
                                                            [httponly] => 1
                                                            [domain] => my.rentfaxpro.com
                                                        )

                                                )

                                            [flags] => Array
                                                (
                                                    [creation] => 1545413467
                                                    [last-access] => 1545413467
                                                    [persistent] => 
                                                    [host-only] => 1
                                                )

                                            [reference_time] => 1545413467
                                        )

                                )

                        )

                )

            [filename:protected] => 
            [data] => 
            [headers] => 
            [status] => 
        )

)

HI Chris,

Thank you so much for reaching back.

I see in the response I am sending dropdown text instead of value for bedrooms and bathrooms.

So how can we send the value of the drop down instead of the drop down text? for the line below.

bedrooms’ => rgar( $entry, ‘15’ ),
bathrooms’ => rgar( $entry, ‘14’ ),

Thank you for your help so far.

I am trying to create a gravity form similar to the html one so I send data and get a response in return:

<form id="run-report-form" class="white-container form-horizontal" action="/integration/report" method="post" novalidate="novalidate">
                    <input id="csrfToken" name="csrfToken" type="hidden" value="xxxxxxxxxxxxxxxxxx">
                    <fieldset>
                        <div class="row-fluid">
                            <div class="control-group">
                                <label class="control-label" for="address">API Key</label>
                                <input id="apiKey" name="apiKey" placeholder="Enter API Key" class="report-input" type="text" value="">
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="control-group">
                                <label class="control-label" for="reportCode">Report Type</label>
                                <select id="reportCode" name="reportCode" class="report-select">
                                    <option value="RISK-SUMMARY">Risk Summary Report</option>
                                    <option value="RISK-DETAIL">Risk Detail Report</option>
                                    <option value="RENT-REPORT">Rent Report</option>
                                    <option value="RENT-PACKAGE">Rent Package</option>
                                    <option value="PRO-FORMA-PACKAGE">ProForma Package</option>
                                </select>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="control-group">
                                <label class="control-label" for="address">Address</label>
                                <input id="address" name="address" placeholder="Enter Address" class="report-input" type="text" value="" autocomplete="off">
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="control-group">
                                <label class="control-label" for="city">City</label>
                                <input id="city" name="city" placeholder="Enter City" class="report-input" type="text" value="">
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="control-group">
                                <label class="control-label" for="state">State</label>
                                <select id="state" name="state" class="report-select">
                                    <option value="-1">--Select State--</option>
                                    <option value="AL">Alabama</option><option value="AK">Alaska</option><option value="AZ">Arizona</option><option value="AR">Arkansas</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DE">Delaware</option><option value="FL">Florida</option><option value="GA">Georgia</option><option value="HI">Hawaii</option><option value="ID">Idaho</option><option value="IL">Illinois</option><option value="IN">Indiana</option><option value="IA">Iowa</option><option value="KS">Kansas</option><option value="KY">Kentucky</option><option value="LA">Louisiana</option><option value="ME">Maine</option><option value="MD">Maryland</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="MS">Mississippi</option><option value="MO">Missouri</option><option value="MT">Montana</option><option value="NE">Nebraska</option><option value="NV">Nevada</option><option value="NH">New Hampshire</option><option value="NJ">New Jersey</option><option value="NM">New Mexico</option><option value="NY">New York</option><option value="NC">North Carolina</option><option value="ND">North Dakota</option><option value="OH">Ohio</option><option value="OK">Oklahoma</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="RI">Rhode Island</option><option value="SC">South Carolina</option><option value="SD">South Dakota</option><option value="TN">Tennessee</option><option value="TX">Texas</option><option value="UT">Utah</option><option value="VT">Vermont</option><option value="VA">Virginia</option><option value="WA">Washington</option><option value="DC">Washington DC</option><option value="WV">West Virginia</option><option value="WI">Wisconsin</option><option value="WY">Wyoming</option>
                                </select>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="control-group">
                                <label class="control-label" for="zip">Zip</label>
                                <input id="zip" name="zip" placeholder="Enter Zip" class="report-input" type="text" value="">
                            </div>
                        </div>
                        <div id="additional-rent-inputs" class="hide">
                            <div class="row-fluid">
                                <div class="control-group">
                                    <label class="control-label" for="propertyType">Property Type</label>
                                    <select id="propertyType" name="propertyType" class="report-select">
                                        <option value="-1">Select Property Type</option>
                                        <option value="1">Single-Family Home</option>
                                        <option value="2">Condo/Apartment/Townhouse</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row-fluid">
                                <div class="control-group">
                                    <label class="control-label" for="bedrooms">Bedrooms</label>
                                    <select id="bedrooms" name="bedrooms" class="report-select">
                                        <option value="-1">Select Bedrooms</option>
                                        <option value="1">1 Bedroom</option>
                                        <option value="2">2 Bedrooms</option>
                                        <option value="3">3 Bedrooms</option>
                                        <option value="4">4 or More Bedrooms</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row-fluid">
                                <div class="control-group">
                                    <label class="control-label" for="bathrooms">Bathrooms</label>
                                    <select id="bathrooms" name="bathrooms" class="report-select">
                                        <option value="-1">Select Bathrooms</option>
                                        <option value="1">1 Bathroom</option>
                                        <option value="1.5">1.5 Bathrooms</option>
                                        <option value="2">2 Bathrooms</option>
                                        <option value="2.5">2.5 Bathrooms</option>
                                        <option value="3">3 Bathrooms</option>
                                        <option value="3.5">3.5 Bathrooms</option>
                                        <option value="4">4 Bathrooms</option>
                                        <option value="4.5">4.5 Bathrooms</option>
                                        <option value="5">5 Bathrooms</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row-fluid">
                                <div class="control-group">
                                    <label class="control-label" for="squareFeet">Square Feet</label>
                                    <input id="squareFeet" name="squareFeet" placeholder="Enter Square Feet" class="report-input" type="text" value="">
                                </div>
                            </div>
                        </div>
                        <div class="pull-right">
                            <button id="submit-button" class="btn btn-primary-action" type="submit">Submit</button>
                        </div>
                    </fieldset>
                </form>

Regards,
Pallavi

To get the label, rather than the value, you need to use some variation of this:

$label = $field->get_value_entry_detail( RGFormsModel::get_lead_field_value( $entry, $field ), $currency = '', $use_text = true, $format = 'html' );

Hi Chris,

Apologies for not being clear.

I get the option text and not the option value from the dropdown.

So when I do something like this:
bedrooms’ =>rgar( $entry, ‘15’ ),

   <select id="bedrooms" name="bedrooms" class="report-select">
              <option value="-1">Select Bedrooms</option>
              <option value="1">1 Bedroom</option>
              <option value="2">2 Bedrooms</option>
               <option value="3">3 Bedrooms</option>
               <option value="4">4 or More Bedrooms</option>
   </select>

I get 1 Bedroom when I want value=“1” for this option.

Regards,
Pallavi

What is the code you are using the get the value currently? Sorry I could not find it when scrolling back through.

Hi Chris,

So when I do

add_action( ‘gform_after_submission_12’, ‘post_to_third_party’, 10, 2 );
function post_to_third_party( $entry, $form ) {
$post_url = ‘https://my.rentfaxpro.com/integration/report’;
$body = array(
‘reportCode’  =>  ‘RENT-REPORT’,
‘address’ => rgar( $entry, ‘4.1’ ),
‘city’  => rgar( $entry, ‘4.3’ ),
‘state’  =>  rgar( $entry, ‘4.4’ ),
‘zip’  =>  =>  rgar( $entry, ‘4.5’ ),
‘propertyType’ => rgar( $entry, ‘10’ ),
‘bedrooms’ => rgar( $entry, ‘15’ ),
‘bathrooms’ => rgar( $entry, ‘14’ ),
‘squareFeet’ => rgar( $entry, ‘17’ ),
);
print_r($body);
GFCommon::log_debug( 'gform_after_submission_12: body =&gt; ’ . print_r( $body, true ) );
$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_after_submission_12: response => ' . print_r( $response, true ) );
}

In the body array above for :
‘bedrooms’ => rgar( $entry, ‘15’ ),
‘bathrooms’ => rgar( $entry, ‘14’ ),

I get the text selected from the dropdown 23%20AM

I get (1 Bedroom) instead of the value for that option which is 1:

Select Bedrooms
1 Bedroom
2 Bedrooms
3 Bedrooms
4 or More Bedrooms

Thank you for all your help so far.

Regards,
Pallavi

Hi Chris,

I get the right values now from the option for bed and bathroom.

The Body that gets sends looks like this:
body => Array
(
[apikey] => xxxxxxx-bf77-45a2-a70f-xxxxxxxx
[reportCode] => RENT-REPORT
[address] => 7224 Nall Ave
[city] => Memphis
[state] => TN
[zip] => 38134
[propertyType] => 1
[bedrooms] => 1
[bathrooms] => 1
[squareFeet] => 3451
)

But the data is not getting send to
$post_url = ‘https://my.rentfaxpro.com/integration/report’;even after receiving the 200 response after the submission I will get a report id in the body of response using which I want to make another post request.

Any help will be helpful.

The code so far:
add_action( ‘gform_after_submission_12’, ‘post_to_third_party’, 10, 2 );
function post_to_third_party( $entry, $form ) {

$post_url = 'https://my.rentfaxpro.com/integration/report';
$body = array(
    'apikey' => 'xxxxxxx-bf77-45a2-a70f-xxxxxxxx',
    'reportCode' => 'RENT-REPORT',
	'address' => rgar( $entry, '4.1' ),
	'city' => rgar( $entry, '4.3' ),
	'state' => 'CA',
	'zip' => rgar( $entry, '4.5' ),
	'propertyType' => rgar( $entry, '10'),
	'bedrooms' => rgar( $entry, '15' ),
           'bathrooms' => rgar( $entry, '14' ),
	'squareFeet' => rgar( $entry, '24' ),
    );

 
  // GFCommon::log_debug( 'gform_after_submission: body => ' . print_r( $body, true ) );
$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
print_r($body);
GFCommon::log_debug( 'gform_after_submission_12: body => ' . print_r( $body, true ) );
GFCommon::log_debug( 'gform_after_submission_12: response => ' . print_r( $response, true ) );
print_r( $response, true );

}

Is there something I am missing ?

When I send the post to the webhook it shows the sent data which is correct as well:
https://webhook.site/#/395b7ba6-b4e8-48d2-893c-e85d0ad0ff05/391c6757-2443-4bf2-95a1-3aa93bfd2444/1

Thank you for your help.

Regards,
Pallavi

Can you share the link to the log file please? The logging statements should still be present and we can see what happened with your updated code.

Hi Chris,

Sure Thank you so much for your help.

I see the response 200 but don’t see anything in body

Regards,
Pallavi

If you get a 200 (Success) response, that means you are correctly connecting to the resource. If the body comes back empty, chances are you are not sending everything you should be, or it’s in the wrong format. I would work with the rentfaxpro support or documentation to see why you are not getting the Report ID, which is what it seems like you should be getting back.

Hi Chris,

Thank you so much for your help.

The Data is finally getting send to third party :grin:

But I get this error instead of the body response :
(
[errors] => Array
(
[http_request_failed] => Array
(
[0] => cURL error 28: Operation timed out after 5001 milliseconds with 0 bytes received
)

    )

[error_data] => Array
    (
    )

)

Regards,
Pallavi

Did that error happen before? I don’t remember it. The cURL error 28 means your server/code cannot connect to the external URL. There can be many reasons for that. I recommend searching for that “cURL error 28” specifically and checking all the possibilities.

https://www.samuelaguilera.com/post/curl-error-28-wordpress

Hi Chris,

I was able to achieve what I was trying to do. Thank you so much for your help with everything.

Regards,
Pallavi

Thanks for the update. How did you ultimately fix it?