Skip Navigation

[Résolu] anchor argument to return to view after save of cred

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to set a different redirect for each parent post ID after CRED save with different CRED forms.

Solution:
CRED offers hook: "cred_success_redirect" to set custom redirect URL after CRED post saved.

Code Example: https://toolset.com/forums/topic/anchor-argument-to-return-to-view-after-save-of-cred/#post-373953

Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-api/#csr
[Section: "also The user can also apply this filter for a specific form (by id)"]

This support ticket is created Il y a 8 années et 1 mois. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Marqué : 

This topic contains 6 réponses, has 2 voix.

Last updated by joshO Il y a 8 années.

Assisted by: Minesh.

Auteur
Publications
#370451
Screen Shot 2016-02-24 at 9.56.47 PM.png
Screen Shot 2016-02-24 at 9.57.50 PM.png

I am trying to:
Return to anchor of grid list on a view after save new record using cred form for that list. I saw this issue and has similar issue but they are returning to a list view https://toolset.com/forums/topic/anchor-argument-in-view/

Looking at this as a possible starting point based on above link , not sure how the anchor tag <a name="competitors"> is passed to Cred. and what to set the Cred form options " Choose what to do after visitors submit this form" Cred form we are testing the id is 698

add_filter('cred_success_redirect', 'custom_redirect_anchor_after_cred_save',10,3);
function custom_redirect_anchor_after_cred_save($url, $post_id, $form_data) {
  if ($form_data['id']==698) 
  {
    $url .= '#' . $post_id;
  }
  return $url;
}

Screen shot show Layout with Grid, button add competitor calls CRED and when save cred i want to go back to the Competitor grid section of the Layout refreshed so we can see the new record.

#370468

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know have you already added the anchor in the view? If no, you should add anchors to your view, please see following tutorial:
=> hidden link

As well as, you need to set $url variable to your desired redirect URL.

I hope this will help you to fix your issue and please feel free to get in touch with me if you need further assistance.

#370482

Yes , I have added anchors to each section of the view. I was testing this function and it works getting us back to main view after cred save but not all the way to the anchor. and its working for multiple forms. What / where would I need to add to get to the anchor? $url .= '#' . $post_id;

Also key point that I did not seem to find when doing this is on CRED form
set "Choose what to do after visitors submit this form:"
= go to a page and choose page name , the same as this form

add_filter('cred_success_redirect', 'custom_redirect_parent',10,3);
function custom_redirect_parent($url, $post_id, $form_data)
{
 
if (($form_data['id']==282) || ($form_data['id']==245) || ($form_data['id']==698 ) || ($form_data['id']==466 ))
 
$parent_id = get_post_meta( $post_id, '_wpcf_belongs_company_id', true);
return get_permalink( $parent_id );

return $url;
 
}
#370484

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've modified your code to your requirement. Could you please try to use following code:

add_filter('cred_success_redirect', 'custom_redirect_parent',10,3);
function custom_redirect_parent($url, $post_id, $form_data)
{
  
if (($form_data['id']==282) || ($form_data['id']==245) || ($form_data['id']==698 ) || ($form_data['id']==466 ))
  
$parent_id = get_post_meta( $post_id, '_wpcf_belongs_company_id', true);
$url = get_permalink( $parent_id );
$url .= '#' . $post_id;
return $url;
  
}

I hope this solution will help you to resolve your issue. Please feel free to get in touch with me if you need further assistance.

#373616

I used your code and it worked for pages that share the same process.

when i have more than one redirect for diff pages, only one of them works. any thoughts

/* Link Product to Program Redirect ********** /

add_filter('cred_success_redirect', 'product_program_redirect',10,3);
function product_program_redirect($url, $post_id, $form_data)
{

if (($form_data['id']==144))

$parent_id = get_post_meta( $post_id, '_wpcf_belongs_program_id', true);
$url = get_permalink( $parent_id );
$hash = "products";
$url .= '#' . $hash;
return $url;
}

/* Link Company to Program Redirect ********** /
add_filter('cred_success_redirect', 'competitor_program_redirect',10,3);
function competitor_program_redirect($url, $post_id, $form_data)
{

if (($form_data['id']==152))

$parent_id = get_post_meta( $post_id, '_wpcf_belongs_program_id', true);
$url = get_permalink( $parent_id );
$hash = "competitors";
$url .= '#' . $hash;
return $url;
}

#373953

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

For multiple forms you can add filter for each of your form:
https://toolset.com/documentation/user-guides/cred-api/#csr
[Section: "also The user can also apply this filter for a specific form (by id)"]

For example:

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)
{
    if ($form_data['id']==12)
        return '<em><u>hidden link</u></em>';
 
    return $url;
}

add_filter('cred_success_redirect_13', 'custom_redirect_for_form_with_id_12',10,3);
function custom_redirect_for_form_with_id_13($url, $post_id, $form_data)
{
    if ($form_data['id']==13)
        return '<em><u>hidden link</u></em>';
 
    return $url;
}

I hope above solution will help you to resolve your issue.

#373981

Its working . Here is the updated code what we did here is , on save go to page and anchor location of where the record was added in a grid. Thanks!

/* *********** Link Product Redirect ********************* */

add_filter('cred_success_redirect_144', 'custom_redirect_for_form_with_id_144',10,3);
function custom_redirect_for_form_with_id_144($url, $post_id, $form_data)
{
if ($form_data['id']==144)
$parent_id = get_post_meta( $post_id, '_wpcf_belongs_program_id', true);
$url = get_permalink( $parent_id );
$hash = "products";
$url .= '#' . $hash;
return $url;
}

/* *********** Link Program Redirect ********************* */

add_filter('cred_success_redirect_152', 'custom_redirect_for_form_with_id_152',10,3);
function custom_redirect_for_form_with_id_152($url, $post_id, $form_data)
{

if ($form_data['id']==152)
$parent_id = get_post_meta( $post_id, '_wpcf_belongs_program_id', true);
$url = get_permalink( $parent_id );
$hash = "competitors";
$url .= '#' . $hash;

return $url;
}

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.