Skip Navigation

[Resolved] Add parameter with filled field data to redirected URL after form sent

This thread is resolved. Here is a description of the problem and solution.

Problem: I have two Forms. When one Form is submitted, I would like to redirect the User to the second Form, but I would like to add a URL parameter based on the selections in Form 1. That URL parameter should be used to preselect one of the fields in Form 2.

Solution: The cred_field shortcode accepts an attribute called "urlparam" that you can use to pre-define field values. For example:

[cred_field field="mobile" post="agent" urlparam="mobilenum"]

Then in the URL:
http://yoursite.com/form-page?mobilenum=123-456-7890

To set a URL parameter value in the redirect URL based on a custom field selection, use the cred_success_redirect API:

add_filter('cred_success_redirect', 'custom_purchase_redirect',10,3);
function custom_purchase_redirect($url, $post_id, $form_data)
{
  if ($form_data['id']==12345) {
    $email = get_post_meta( $post_id, 'wpcf-e-mail', true );
    $phone = get_post_meta( $post_id, 'wpcf-telefonni-cislo', true);
    $redirect = $url . "?fapi-form-email=" . $email . "&fapi-form-phone=" . $phone;
    return $redirect;
  }
  return $url;
}

Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

This support ticket is created 6 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Christian Cox 6 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1088407

Tell us what you are trying to do?

I am trying to Add a parameter to URL after form submission. The idea is:

Before form
1) user go to page with language course (english, spanish, german, france) and click on buy course.
2) Button redirect user to form which have dropdown menu called languages

is possible to have the dropdown pre selected to the right language if I add a parameter to URL? Something like:

hidden link --- pre select english in dropdown
or
hidden link --- pre select german in dropdown
etc...

And also some other dropdowns, if user come from other page like pricing tables:

hidden link --- pre select german in dropdown, 10 x 50 minutes in dropdown and native speaker in speaker dropdown.

In form
1) User fill in its Skype name and e-mail, and some other custom post fields.
2) User submit the form
3) After form sent page will redirect to the post
- and to the post url are added some variables like this:

hidden link ?fapi-form-email=[types field='e-mail' output='raw'][/types]&fapi-form-phone=[types field='telefonni-cislo'][/types]

or &fapi-form-email=[types field='e-mail' output='raw'][/types]&fapi-form-phone=[types field='telefonni-cislo'][/types] if the ? symbol is already used in url.

Can this be somehow achieved?

#1088680

is possible to have the dropdown pre selected to the right language if I add a parameter to URL?
Yes, the cred_field shortcode accepts an attribute called "urlparam" that you can use to pre-define field values. For example:

[cred_field field="mobile" post="agent" urlparam="mobilenum"]

Then in the URL:
http://yoursite.com/form-page?mobilenum=123-456-7890

The cred_field shortcode is documented here:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

3) After form sent page will redirect to the post and to the post url are added some variables like this:
In the normal WooCommerce and Forms Commerce workflow, after the Commerce Form is submitted the User is sent through WooCommerce's checkout process. Are you saying you do not want to go to checkout before the User sees the new post? I think I do not understand fully.

#1089263
2nd step the post.png
toolset form 1st step.png

Hey! Thank you for the 1st reply.

About the secondary problem. It´s not a woocommerce page at all. The payment is made with special payment forms embeded from the 3rd side.

So the flow is:

1) Select the right course //set the parameters to the URL which pre define the dropdowns in toolset form
2) fill the Toolset form ( hidden link ) //after sent set up the parameters to the url which pre define the embedded payment form in 3rd step
3) fill the embeded payment form

I saw a urlparam field at the send button of form, but it does not send the parameter to the url.

#1089400

I was thinking about it, and maybe it can be done on the post page itself somehow?

Maybe its possible to set something like:

if post type = mycustomorder then when open post write this parameters with custom field values to the URL..

just thinking..

#1089490

Okay thanks, I understand better now. The best way to customize a Form redirect URL like this is to use the Forms API cred_success_redirect: https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

Here is an example you can add to your child theme's functions.php file:

add_filter('cred_success_redirect', 'custom_purchase_redirect',10,3);
function custom_purchase_redirect($url, $post_id, $form_data)
{
  if ($form_data['id']==12345) {
    $email = get_post_meta( $post_id, 'wpcf-e-mail', true );
    $phone = get_post_meta( $post_id, 'wpcf-telefonni-cislo', true);
    $redirect = $url . "?fapi-form-email=" . $email . "&fapi-form-phone=" . $phone;
    return $redirect;
  }
  return $url;
}

Change 12345 to match the numeric ID of your Form.