Submitting form entry to external url [RESOLVED]

Hi,
I have a single line text form that allows a user to enter a number. I need that form to submit to an external url and add the entry from my form to the url of where I’m submitting to.

I found this that allows me to post to a url but obv doesn’t include my form data.
How do I post to a URL « Gravity Support Forums (gravityhelp.com)

So for example my form is at www[dot]site1[dot]com and a user enters 12345 into my form.

This then actions to www[dot]site2[dot]com but I need to add /12345 to the end of the url.

Any pointers would be appreciated.
TIA

Settings > Confirmations > Confirmation Type: Redirect
Redirect URL: www.site2.com
Pass Field Data via Query String: remote_field_name={Number:1}

Then your remote recipient system obviously needs to be set up to receive that data.

1 Like

Thanks Phil, this almost works perfectly. However, I just need to remove the ? it’s inserting into the url.

So at the moment it’s loading www[dot]site2[dot]com/?12345 and just need it to be /12345

Hi Alan. In that case, don’t check the box to use the query string, and enter your URL and the merge tags for your field values (like {Number:1}) in the redirect URL area. That will send the data to your URL with the number appended and no question mark. Like this:

Let us know if you need anything else.

Hi Chris, thanks for your reply.

I actually tried that but it didn’t quite work either. The url I’m redirecting to has a # in it and it’s causing what you’ll see below. Didn’t mention the # in my original post as didn’t realise it’d be relevant.

Redirect url in settings:
https://site[dot]com/#/{Number:1}

Resulting url of the redirect:
https://site[dot]com/?#/12345

Thanks

Hi Alan. Can you please export this form and send me the JSON file (email to chris@rocketgenius.com). You can see how to export a form here: Exporting a Form - Gravity Forms Documentation

I’ll take a look. Thank you.

Thanks Chris. Email sent.

Hi Alan. I took a look at your simple form and I can see what you mean. I think the # is messing with things. That’s OK though - we can work around it. Please try this code:

<?php
add_filter( 'gform_confirmation', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
	// apply to form 82 only
	if( $form['id'] == '82' ) {
		$url = 'https://xbulk.no/#/' . rgar ( $entry, '1' );
		$confirmation = array( 'redirect' => $url );
	}
	// return the confirmation either way, modified or not
	return $confirmation;
}

That code will apply to form 82. Change 82 in the code to your form ID. If you need to apply this to more forms or all forms, let me know and we’ll work out how to do that.

This is PHP code which can go into your theme functions.php file or a custom functionality plugin if you are using one, or you can use a plugin like this to separate the code from the theme:

Try that out and let me know how it works.

2 Likes

That’s worked perfectly Chris. Thanks to you, and to Phil a little earlier on in the thread, for superb support with my issue!

2 Likes

Awesome, thank you for the update.