Skip Navigation

[Resuelto] pass newly created post id with url parameter to target page

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I would like to use the Forms API to redirect to a specific URL, including a parameter set by the new post ID.

Solution: The second parameter in the callback function, $post_id, contains the ID of the created or edited post.

add_filter('cred_success_redirect', 'custom_purchase_redirect',10,3);
function custom_purchase_redirect($url, $post_id, $form_data)
{
  if ($form_data['id']==60) {
    $redirect = $url . "?fit=" . $post_id;
    return $redirect;
  }
  return $url;
}

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

This support ticket is created hace 5 años, 10 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por Ido Angel hace 5 años, 10 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#1193975

hey,
i have a cred form where the user submit a new "company", then is being redirected to an inner payment page on the site.
I wanted to add to the payment form (a stripe form, not cred) a unique id equal to the id of the newly created company. But I only managed to get a custom field, and not the new company post id.

My code:

add_filter('cred_success_redirect', 'custom_purchase_redirect',10,3);
function custom_purchase_redirect($url, $post_id, $form_data)
{
  if ($form_data['id']==60) {
    $companyid = get_post_meta( $post_id, 'wpcf-company-name', true );
    $redirect = $url . "?fit=" . $companyid;
    return $redirect;
  }
  return $url;
}

My jQuery to populate the stripe form input field:

jQuery(document).ready(function( $ ){
	var str = window.location.href;
  var credReferrer = str.match("fit=(.*)&cred_referrer_form_id");
  $(".wpfs-payment-form .control-group input[id='fullstripe-custom-input__fitness-inline-01__1']").val(credReferrer[1]);
});

I tried using "wpv-post-id" instead of "wpcf-company-name", but that resulted in nothing.

Any chance of getting this done somehow? I know the notification email sent after the cred submission CAN include the new post id.

thanks!

Ido

#1193976

Hey the second parameter, $post_id, in the cred_success_redirect callback is the ID of the post that was just created or edited. You're already using it to get the post meta value, but that's not necessary. You can just use $post_id directly instead:

add_filter('cred_success_redirect', 'custom_purchase_redirect',10,3);
function custom_purchase_redirect($url, $post_id, $form_data)
{
  if ($form_data['id']==60) {
    $redirect = $url . "?fit=" . $post_id;
    return $redirect;
  }
  return $url;
}

Let me know if I misunderstood what you're trying to accomplish.

#1193987

My issue is resolved now. Thank you! Perfect as always, Chris!!