Solution:
Please use this code, and make sure to properly change field slug in the below code:
add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data)
{
// I have corrected the ID
if ($form_data['id']==7696)
{
$field1 = '';
$field2 = ''; // I just changed it this way to make me understand better
if(isset($_POST['wpcf-field1-slug']))
{ // I added this opening bracket
$field1 = $_POST['wpcf-field1-slug'];
}; // I added this closing bracket and the semi-colon
if(isset($_POST['wpcf-field2-slug']))
{
$field2 = $_POST['wpcf-field2-slug'];
};
header('location: http://thedirectedpage.something/?field1='.$field1.'&field2='.$field2.''); // I added the necessary apostrophe(s)
exit;
}
}
I want to send values from a form created using CRED, to a 3rd party page using URL.
My CRED form is in this page: hidden link
In that form, the Submit button opens up a blank page that is set to redirect to the following URL of a 3rd party website:
hidden link A090906
Note that the URL contains values, eg. aQIF2017, that would be inserted into fields, eg. kod_epay, on that 3rd party page/form.
Is it possible to replace the values with data that has just been collected in our CRED form, to make the URL something like this:
hidden link from toolset field1]&amount=880.00&id_trans=[value from toolset field2]&bill_email=[value from toolset field3]&bill_desc=[value from toolset field4]
Or is there a different way of implementation? I have no control over the 3rd party page.
Other than that, this falls into pure Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/). So we recommend to contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/
I have tried with the cred_submit_complete add_function. But I don't see any results.
Here's what I did:
- Following the link that you provided, I added the following code into my function.php file, just to try out with a simple redirecting command:
add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==8142)
{
// user can overwrite everything here, eg redirection, messages displayed etc..
// eg redirect regardless of form settings
header('location: <em><u>hidden link</u></em>');
}
}
- After filling up the form and submitting it, I was not taken to the redirected url, but rather back to a blank form.
Thanks. I used the code you provided but it didn't work. Then I modified the code and finally got it to work. The final code looks something like this:
add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data)
{
// I have corrected the ID
if ($form_data['id']==7696)
{
$field1 = '';
$field2 = ''; // I just changed it this way to make me understand better
if(isset($_POST['wpcf-field1-slug']))
{ // I added this opening bracket
$field1 = $_POST['wpcf-field1-slug'];
}; // I added this closing bracket and the semi-colon
if(isset($_POST['wpcf-field2-slug']))
{
$field2 = $_POST['wpcf-field2-slug'];
};
header('location: <em><u>hidden link</u></em>'.$field1.'&field2='.$field2.''); // I added the necessary apostrophe(s)
exit;
}
}