Hello,
I have created a Views to display users. As not filter is avialable for this kind of Views, I have created a Cred (id : 5833) in order to define parameters and associate a red_success_redirect hook to this form. This Cred is used to modify a specific post (I do not need to create any postype, just get the filter info and let the hook works).
The Cred is define to redirect to a specific page after submission.
Here is the Cred code :
[credform]
[cred_field field='form_messages' class='alert alert-warning']
<div class="col-sm-3">
<label>Recherche par nom</label>
[cred_generic_field type='textfield' field='recherche_nom']
{
"required":0,
"default":""
}
[/cred_generic_field]
</div>
<div class="col-sm-3">
<label>Recherche par n° de carte</label>
[cred_generic_field type='numeric' field='recherche_nca']
{
"required":0,
"validate_format":1,
"default":""
}
[/cred_generic_field]
</div>
<div class="col-sm-3">
<label>Recherche par ID</label>
[cred_generic_field type='numeric' field='recherche_id']
{
"required":0,
"validate_format":1,
"default":""
}
[/cred_generic_field]
</div>
<div class="col-sm-3">
[cred_field field='form_submit' output='bootstrap' value='Envoi' class='et_pb_button']
</div>
[/credform]
And the hook :
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
add_filter('cred_success_redirect_5833', 'redirect_recherche_adherent',10,3);
function redirect_recherche_adherent($url, $post_id, $form_data)
{
if ($form_data['id']==5833)
{
$nom = "";
$nca ="";
$nid ="";
if (isset($_POST['recherche_nom']))
{
$nom = $_POST['recherche_nom'];
if ($nom != "")
{
$nomr = "nom=".$nom."&";
}
else
{
$nomr="";
}
}
if (isset($_POST['recherche_nca']))
{
$nca = $_POST['recherche_nca'];
if ($nca != "")
{
$ncar = "carteadh=".$nca."&";
}
else
{
$ncar="";
}
}
if (isset($_POST['recherche_id']))
{
$nid = $_POST['recherche_id'];
if ($nid != "")
{
$nidr = "users-filter=".$nid;
}
else
{
$nidr="";
}
}
$newurl = "<em><u>hidden link</u></em>?".$nomr.$ncar.$nidr;
return $newurl;
error_log( print_r( "test-url : ".$newurl , true ) );
}
return $url;
}
// Put the code of your snippet below this comment.
When I edit the error_log file, everything seems fine and I'm getting the right url.
Now, in the front end, after submitting the form, I'm redirected to this url :
hidden link instead of having something like hidden link
For info, I have another issue that is reported in this thread : https://toolset.com/forums/topic/how-to-insert-a-user-modify-form/
Any idea?
Regards
Pat
Hi Pat, can you try changing the URL to something else temporarily, like this:
//$newurl = "<em><u>hidden link</u></em>?".$nomr.$ncar.$nidr;
$newurl = "<em><u>hidden link</u></em>";
return $newurl;
1. Is the redirect to /something-different/ working as expected?
2. Can you confirm the site is on HTTP, and not on HTTPS?
Hi Christian,
Thanks for helping. I have already tried this but without success. I'm always redirected to the same url : hidden link
5833 is the ID of the form used to make the filtering.
I confirm I am in http as this site is into development and not linked to the final domain name for the moment.
Regards
Pat
The problem could be here:
if ($form_data['id']==5833)
The correct attribute should be 'form_id', not 'id', as described here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
However, since you have added _5833 to the cred_success_redirect action name, this conditional probably isn't even needed.
Hi Christian,
As I was not sure that the form was correctly defined, I have added the cred_success_redirect_5833
Nevertheless, I just tried with the if ($form_data['form_id']==5833) but this is not changing anything.
Any idea?
Regards
Pat
Hi Christian,
In the meantime, I have tried to insert the form (5833) directly into a page and I'm getting this error message in the front end :
Form type and post type do not match
Hope this helps to define the global issue.
Regards
Pat
Hi Christian,
After checking a little more, the "Form type and post type do not match" issue is there only if I use an edit form. If I use a create form, then, I'm getting the same issue than before (the redirection is not working and the url finishes with ?cred_referrer_form_id=5833).
Regards
Pat
Hi Christian,
I have checked again and it seems another code snippet was the rootcause of this issue. In fact, both was using the cred_success_redirect function and the way the form id was restricted was getting this issue (I think both snippets were trying to redirect to different pages !!!)
So, I have changed the way Cred form was specified by using : cred_success_redirect_form-id and now, everything is fine.
Thanks for your patience and sorry for not having better analysed the situation before !
Regards
Pat