Tell us what you are trying to do?
I have a 'Select Field' with two options in a New Post Form.
I need to redirect to an specific url after Submitting if one of those two fields are selected.
So, for example:
If "A" field is selected in the form, Submit button goes to hidden link
If "B" field is selected in the form, Submit button goes to hidden link
Is there any documentation that you are following?
I tried this topics, but I can't understand them and after trying blindly I can't make it work on my site.
https://toolset.com/forums/topic/cred-form-conditional-submit-redirects-array/
https://toolset.com/forums/topic/detecting-a-generic-field-checkbox-on-submit-for-a-conditional-redirect-url/
What is the link to your site?
Working on a development site
I think this is exactly what you need https://toolset.com/forums/topic/multiple-submit-buttons-on-cred-form/
Can you confirm that the solution there is what you look for?
It allows hooking a custom code to redirect on several different URLs depending on the button pressed.
Hi Beda.
Thanks for your answer.
Yes, I think it¡s very close of what I¡m looking for, but I'm a little bit confused.
(Sorry I do not now JS at all...)
What I have now is this
add_action('cred_save_data', 'save_data_form_837',10,2);
function save_data_form_837($post_id, $form_data) {
if ($form_data['id']==837) {
if (isset($_POST['form_submit_1'])) {
update_post_meta($post_id, 'tipo-de-empresa', 'Profesional');
}
if (isset($_POST['form_submit_2'])) {
update_post_meta($post_id, 'tipo-de-empresa', 'Empresa');
}
}
}
add_filter('cred_success_redirect', 'custom_redirect_form_abc',10,3);
function custom_redirect_form_abc($url, $post_id, $form_data)
{
if ($form_data['id']==837){
if (isset($_POST['form_submit_1'])) {
$url = "<em><u>hidden link</u></em>";
}
}
return $url;
if ($form_data['id']==837){
if (isset($_POST['form_submit_2'])) {
$url = "<em><u>hidden link</u></em>";
}
}
return $url;
}
I also tried this, just testing, but nothing happens
add_action('cred_save_data', 'save_data_form_1977',10,2);
function save_data_form_1977($post_id, $form_data) {
if ($form_data['id']==1977) {
if (isset($_POST['form_submit_1'])) {
update_post_meta($post_id, 'tipo-de-empresa', 'Profesional'); {
$url = "<em><u>hidden link</u></em>";
}
}
return $url;
}
if (isset($_POST['form_submit_2'])) {
update_post_meta($post_id, 'tipo-de-empresa', 'Empresa');{
$url = "<em><u>hidden link</u></em>";
}
}
return $url;
}
}
}
and in the Form submit button I have only one button, like this, just because I read you talking about only one button can be use on a form (and I guess the diference in what url uses the button is on the JS code).
[cred_field field="form_submit" output="bootstrap" value="Submit 1" class="btn btn-primary btn-lg"]
As you can see, I'm not very expertise... I think I mess up with the two posts (Yours: https://toolset.com/forums/topic/multiple-submit-buttons-on-cred-form/ and Christian's: https://toolset.com/forums/topic/second-submit-form-button-with-custom-redirect-to-page/#post-1162983)
If you only have one submit button, then none of the code examples here are very helpful. Can you show me the select field options in wp-admin? Go to Toolset > Custom Fields > Post Fields and open the select field options. Take a screenshot showing the select field options and values, and include that in your next reply. I am attaching an example here showing what you should include.
Then, please copy the entire Form code and paste it in your next reply so I can review everything in the Form. I'll take a look and give you some more feedback.
Hi Christian!
🙂
Thanks a lot for your answer.
I attached you the screenshot as you asked.
And here you have my form
<!---- Formulario de condicional correcto --->
<div class="panel panel-primary">
<div class="panel-heading">
<div class="panel-title" style="color:white";><center><font size="4"><strong>[wpml-string context='wpv-views']Información[/wpml-string]</strong></font></center>
</div>
</div>
[credform]
<br>
<div class="panel-body">
<strong><center><h3><p style="color:grey">[wpml-string context='wpv-views']Datos de empresa / profesional[/wpml-string]</h3></center></strong>
<div class="panel-footer">
<div class="form-group">
<label><h5>[wpml-string context='wpv-views']Nombre *[/wpml-string]</h5></label>
[cred_field field="post_title" class="form-control" output="bootstrap"]
</div>
<div class="row">
<div class="col-sm-6"><div class="form-group">
<label><h5>[wpml-string context='wpv-views']Población *[/wpml-string]</h5></label>
[cred_field field="poblacion-guia-produccion" force_type="field" class="form-control" output="bootstrap"]
</div></div>
<div class="col-sm-6"><div class="form-group">
<label><h5>[wpml-string context='wpv-views']Provincia *[/wpml-string]</h5></label>
[cred_field field="provincia-guia-produccion" force_type="field" class="form-control" output="bootstrap"]
</div></div>
</div>
</div>
<br>
<strong><center><h3><p style="color:grey">[wpml-string context='wpv-views']Información de contacto[/wpml-string]</h3></center></strong>
<div class="panel-footer">
<div class="row">
<div class="col-sm-6"> <div class="form-group">
<label><h5>[wpml-string context='wpv-views']Persona de contacto *[/wpml-string]</h5></label>
[cred_field field="persona-de-contacto-guia-produccion" force_type="field" class="form-control" output="bootstrap"]
</div></div>
<div class="col-sm-6"><div class="form-group">
<label><h5>[wpml-string context='wpv-views']Teléfono *[/wpml-string]</h5></label>
[cred_field field="telefono-guia-produccion" force_type="field" class="form-control" output="bootstrap"]
</div></div>
</div>
<div class="row">
<div class="col-sm-6"><div class="form-group">
<label><h5>[wpml-string context='wpv-views']Email *[/wpml-string]</h5></label>
[cred_field field="email-guia-produccion" force_type="field" class="form-control" output="bootstrap"]
</div></div>
<div class="col-sm-6"><div class="form-group">
<label><h5>[wpml-string context='wpv-views']Web[/wpml-string]</h5></label>
[cred_field field="web-guia-produccion" force_type="field" class="form-control" output="bootstrap"]
</div></div>
</div>
</div>
<br>
<strong><center><h3><p style="color:grey">[wpml-string context='wpv-views']Servicios[/wpml-string]</h3></center></strong>
<div class="panel-footer">
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label><h5>[wpml-string context='wpv-views']Tipo[/wpml-string]</h5></label>
[cred_field field='tipo-de-empresa' force_type='field' class='form-control' output='bootstrap']
</div>
</div>
<div class="col-sm-8">
<label><h5>[wpml-string context='wpv-views']Categorías *[/wpml-string]</h5></label>
<br>
[cred_show_group if="( $(tipo-de-empresa) eq 'Profesional' )" mode="fade-slide"]
<div class="js-example-basic-multiple-limit">
[cred_field field='categoria-guia-produccion-prof' force_type='taxonomy' output='bootstrap' display='select' class='js-example-basic-multiple-limit select2']
<i class="texto-descriptivo"> Tres categorías como máximo</i> </div>
[/cred_show_group]
[cred_show_group if="( $(tipo-de-empresa) eq 'Empresa' )" mode="fade-slide"]
<div class="js-example-basic-multiple-limit">
[cred_field field='categoria-guia-produccion-emp' force_type='taxonomy' output='bootstrap' display='select' class='js-example-basic-multiple-limit select2']
<i class="texto-descriptivo"> Tres categorías como máximo</i> </div>
[/cred_show_group]
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label><h5>Idiomas en los que se atiende *</h5></label>
<br>
<br>
[cred_field field="idiomas-guia-produccion" force_type="field" class="form-control" output="bootstrap"]
</div>
</div>
</div>
</div>
<br>
<strong><center><h3><p style="color:grey">Redes sociales</h3></center></strong>
<div class="panel-footer">
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<h5>Facebook</h5>
[cred_field field='facebook-guiaprod' force_type='field' class='form-control' output='bootstrap']
<hr>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<h5>Twitter</h5>
[cred_field field='twitter-guiaprod' force_type='field' class='form-control' output='bootstrap']
<hr>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<h5>Instagram</h5>
[cred_field field='facebook-guiaprod' force_type='field' class='form-control' output='bootstrap']
<hr>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<h5>Youtube</h5>
[cred_field field='youtube-guiaprod' force_type='field' class='form-control' output='bootstrap']
<hr>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<h5>Vimeo</h5>
[cred_field field='vimeo-guiaprod' force_type='field' class='form-control' output='bootstrap']
<hr>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<h5>LinkedIn</h5>
[cred_field field='linkedin-guiaprod' force_type='field' class='form-control' output='bootstrap']
<hr>
</div>
</div>
</div>
</div>
<br>
<br>
[cred_field field="form_submit" output="bootstrap" class="btn btn-primary btn-lg"]
[/credform]
Only for be more clear, if you need.
What I need is:
If a user select the 'Tipo de empresa' option "Empresa" I need to send him to a specific form in a url (let's call it hidden link) and if select "Profesional" to another form (let's call it hidden link)
I'm not sure when you told me "If you only have one submit button..." because, I only have one button because I thought it's only possible to have one Submit button working as Beda told in this ticket
https://toolset.com/forums/topic/multiple-submit-buttons-on-cred-form/
but probably I didn't understood correctly.
Anyway, the simplest solution to my problem will be perfect.
Thanks a lot Christian!!!
🙂
Okay thanks for the information. You do not need the cred_save_data code, because your Form is already modifying the tipo-de-empresa field successfully. You only need the redirection code. Here is an update:
add_filter('cred_success_redirect', 'custom_redirect_form_abc',10,3);
function custom_redirect_form_abc($url, $post_id, $form_data)
{
if ($form_data['id']==837){
if ( get_post_meta($post_id, 'wpcf-tipo-de-empresa', true ) == 'Empresa') {
$url = "<em><u>hidden link</u></em>";
}elseif ( get_post_meta($post_id, 'wpcf-tipo-de-empresa', true ) == 'Profesional') {
$url = "<em><u>hidden link</u></em>";
}
}
return $url;
}
You should change 837 to match your Form ID, if necessary. You can also change the URLs if necessary.
My issue is resolved now. Thank you!