Hello Waqar!
Sorry to bother you again with this job project but I am stuck again and I tried to solve it in all ways. The basic problem that post edit shortcodes don't work. I used those many times I've had no problems with those in other projects. As an alternate method I tried to create a page and inserted the post edit for there, and I created the link to that appending the ?post=123 but shows no post form. I triple checked access settings too so that's not the problem. I give you access to the admin and I send you an Employer user credentials too to check it.
Hi,
Thank you for waiting.
During troubleshooting, I noticed that in the Elementor content of the page "Profil Angajator", the "Employer profile - Edit" form is added but with the option to edit the current post.
( screenshot: hidden link )
This isn't correct in this case, since this edit form is not placed on a single "employer" page, but it is actually on a standalone page.
To fix this, you can remove this form's widget and instead add a simple text widget and include the edit form's shortcode like this:
[cred_form form="employer-profile-edit" post="[wpv-search-term param='post']"]
Please note how I've used the "wpv-search-term" shortcode inside the form's shortcode to get ID from the URL parameter "post".
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-search-term )
As for the redirection of the form to post being edited, you can include a function attached to the "cred_success_redirect".
( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect )
For example:
add_filter('cred_success_redirect', 'custom_redirect_same_post',10,3);
function custom_redirect_same_post($url, $post_id, $form_data)
{
$form_array = array(163);
if (in_array($form_data['id'], $form_array)) {
$url = get_the_permalink($post_id);
return $url;
}
}
regards,
Waqar
Thank you very much Waqar, the cred form work corectly like this. I should have think about this solution myself too because I already used this approach somewhere. But you know there is a saying in Hungarian that "One doesn't see the forest from the tree". I guess I fell into this error with this... So I'm very grateful you helped me out with this 🙂
Do you have an idea why the normal post edit links don't work?
In the redirect code I guess I can add mutliple form IDs for those forms I want to redirect to show the saved post. I'll try that tomorrow.
I have another case though especially with the profile related posts where I want to redirect to the profile page after submit. I should add simply the URL of the profile page to $url ?
Do you have idea why these actions after submit don't work? Is it some bug in Forms?
I decided to send back the user to the profile page after profile-related form saves. I created this code based on your example:
/* go to profile page after cred success */
add_filter('cred_success_redirect', 'custom_redirect_toprofile',10,3);
function custom_redirect_toprofile($url, $post_id, $form_data)
{
$form_array = array(114, 163, 154, 231, 84, 113);
if (in_array($form_data['id'], $form_array)) {
if (ICL_LANGUAGE_CODE == "ro")
$url = '<em><u>hidden link</u></em>';
elseif (ICL_LANGUAGE_CODE == "hu")
$url = '<em><u>hidden link</u></em>';
return $url;
}
}
But the forms still reload just themselves. Have I made an error in the code?
Thank you for sharing the update.
During troubleshooting, I noticed that in multiple functions attached to the "cred_success_redirect" hook, the "return $url;" line needed to be outside the if condition.
Example:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
$form_array = array(225, 226, 230, 167, 168, 169);
if (in_array($form_data['id'], $form_array)) {
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
}
return $url;
}
/* go to profile page after cred success */
add_filter('cred_success_redirect', 'custom_redirect_toprofile',10,3);
function custom_redirect_toprofile($url, $post_id, $form_data)
{
$form_array = array(114, 163, 154, 231, 84, 113);
if (in_array($form_data['id'], $form_array)) {
if (ICL_LANGUAGE_CODE == "ro")
$url = '<em><u>hidden link</u></em>';
elseif (ICL_LANGUAGE_CODE == "hu")
$url = '<em><u>hidden link</u></em>';
}
return $url;
}
add_filter('cred_success_redirect', 'custom_redirect_tocandidateprofile',10,3);
function custom_redirect_tocandidateprofile($url, $post_id, $form_data)
{
$form_array = array(86, 116);
if (in_array($form_data['id'], $form_array)) {
if (ICL_LANGUAGE_CODE == "ro")
$url = '<em><u>hidden link</u></em>';
elseif (ICL_LANGUAGE_CODE == "hu")
$url = '<em><u>hidden link</u></em>';
}
return $url;
}
This should fix the redirection issue and I apologize I missed this detail in my example code snippet earlier.
Thank you very much Waqar! Everything works perfectly! My issue is resolved now.