Skip Navigation

[Resolved] Post edit link for form is not working

This support ticket is created 4 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by jozsefG 4 years ago.

Assisted by: Waqar.

Author
Posts
#1834277

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.

#1834345
#1835627

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

#1835655

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?

#1836587

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?

#1840757

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.

#1845579

Thank you very much Waqar! Everything works perfectly! My issue is resolved now.