Saltar navegación

[Resuelto] Redirect to url + ID after form submit

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

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

Zona horaria del colaborador: America/Jamaica (GMT-05:00)

Este tema contiene 13 respuestas, tiene 2 mensajes.

Última actualización por TomW5440 4 years, 1 month ago.

Asistido por: Shane.

Autor
Mensajes
#2339035

Tell us what you are trying to do?

Hi there,
I'm trying to setup a redirection to previous post on form submit. I guess I need to use a custom hook for this? I see in the docs there's an example -

//This filter can also be applied for a specific form, using the form ID:
add_filter('cred_success_redirect_12', 'custom_redirect_for_form_with_id_12', 10, 3);
function custom_redirect_for_form_with_id_12( $url, $post_id, $form_data )
{
$newurl = 'enlace oculto';
return $newurl;
}

The form in question is a child edit form(CPT comment) and it's parent id (CPT member) is parsed from the previous post. So I want to know how I can use this parent ID in the webhook to redirect it back after form submit?

Something like -
$newurl = 'enlace oculto ';

Any help appreciated, thank you!

#2339101

Shane
Colaborador

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Tom,

Thank you for getting in touch.

Does the URL to the form has the Parent ID in the url already?

Please let me know.
Thanks,
Shane

#2339153

No not parent post id but it does have the comment title in the url.
e.g. enlace oculto

Within the form I have a hidden field set as:
Default slug: @member-comment.child
Default field value: [wpv-post-id]

The url to the form is a link with a parent member loop using this shortcode:
[toolset-edit-post-link content_template_slug='edit-comment' target='self']Edit comment[/toolset-edit-post-link]

Thanks,
Tom

#2339165

Shane
Colaborador

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Tom,

Thank you for the information.

Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?

Please me with a link to where I can navigate to the child post form.

I've enabled the private fields for your next response.

Thanks,
Shane

#2339177

Shane
Colaborador

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Tom,

You can use this to get the parent post id.

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    $parent_id = get_the_ID();
    if ($form_data['id']==368)
        return '<em><u>enlace oculto</u></em>';
   
    return $url;
}

Note i've added the $parent_id variable that gets the ID of the current post. You will see this function in Toolset -> Settings -> Custom Code.

All that's needed is for you to add the redirection URL and include the $parent_id variable in the url.

Thanks,
Shane

#2339191

Thank you so much I really appreciate your help!
I notice the form_data ID in the code is for the New comment form not the Edit comment form? I changed the ID to 434 but either way it's not actually redirecting me after submit. Did it work for you?

#2339753

Shane
Colaborador

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Tom,

Thank you for the clarity.

The problem that we are encountering now is that there isn't a way for me to get the parent id unless you've added the relationship field to the edit form.

I can go ahead and do this and then restructure the code to work with the parent field but please let me know if this is ok.

Thanks,
Shane

#2339823

Hi Shane
That sounds great thank you!
Can the relationship field can be hidden on front end? If so please go ahead. Thank you.

#2339901

Shane
Colaborador

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Tom,

This should now be working.

Thanks,
Shane

#2339925

Thank you Shane.
The member id is in the url after forum submit but the redirect still doesn't work properly. It doesn't redirect to single member but all members.
Is this because id and not slug in the url? enlace oculto.

#2339931

Shane
Colaborador

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Tom,

I misinterpreted, you want it to redirect to the member that you're editing the comment for ?

Please let me know .

Thank,
Shane

#2339947

"I misinterpreted, you want it to redirect to the member that you're editing the comment for ?" Yes exactly that.
Thank you Shane.

#2339951

Shane
Colaborador

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Tom,

I've made an adjustment to the code and it works now.

Thanks,
Shane

#2340747

That's it! My issue is resolved now. Thank you Shane.