Rediect to Thanks page on Public Form

0

I'm currently using the following the form.php so that when a public form has bee submitted the user is then redirected to a thanks page. The problem is that it's always the same thanks page and I would like to direct them depending on which public form they have submitted. Is that possible?

My current code is:

jQuery.ajax({
type: "post",
url: "<?php echo PODS_URL; ?>/ajax/api.php",
data: "action=save_pod_item&"+data.join("&"),
success: function(msg) {
    if ("Error" == msg.substr(0, 5)) {
        alert(msg);
    }
    else {
        window.location = "<?php echo get_bloginfo('url'); ?>" + "/thanks";
    }
    jQuery(".btn_save").attr("disabled", "");
} });

I have two public forms and would like to direct to one of two thanks pages or at least have different thanks text on the page.

Any help with this would be greatly appreciated.

asked Jun 25 '10 at 8:21

daretothink

11

add comment
enter at least 15 characters

8 Answers

1

Putting that php code block into a Pods template is not going to work in this instance. You can either create a separate theme template file just for the form page and put all the php code except for the 'echo' statement at the top (I assume you want the actual form to display in the content area somewhere). Otherwise, if you still want to use a pods template and shortcode, add an action hook in your theme's functions.php file to handle the redirect:

<?php

function check_form_redirect() {
    $saved_pod_id = pods_sanitize($_GET['saved_pod_item']);
    $Record = new Pod('member',$saved_pod_id);
    if(is_numeric($saved_pod_id) && $Record->data) {
        wp_redirect(get_bloginfo('url').'/thanks');
    }
}

add_action('wp','check_form_redirect');

?>

This function would have to be modified slightly to include multiple thank you pages. Probably the easiest way is to use 'is_page()' (http://codex.wordpress.org/Function_Reference/is_page) in IF statements to decide which thank you page to use, but there are other ways as well. Personally, I would just make a separate theme template file, because I like the added control of displaying exactly what I want on the page instead of relying on pods templates and shortcodes.

answered Jun 27 '10 at 1:32

clarinetlord

456

Hey guys, Been wrestling with this problem myself and not managed to get any of these solutions working - think it has something to do with the Thesis theme outputting data early! Anyway, I got round this by making the small edit to the Ajax code as described then placing a conditional in the page code like so: <?php $saved_pod_id = pods_sanitize($_GET['saved_pod_item']); $Record = new Pod('application_form',$saved_pod_id); if(is_numeric($saved_pod_id) && $Record->data) { ?> Your application form has been received. blah blah... Thank you. <? } else { $pods = new Pod('course_application_form'); echo $pods->publicForm(); } ?> Not entirely sure if this is a good way to do this or not - but it does work :-) Looking forward to Pods2 when hopefully this stuff will be a bit easier/less hacky! Cheers Mungo – mungo Jan 4 '11 at 5:11
oops... sorry about the formatting fail! – mungo Jan 4 '11 at 5:13
add comment
enter at least 15 characters
1

Hey guys,

Been wrestling with this problem myself and not managed to get any of these solutions working - think it has something to do with the Thesis theme outputting data early!

Anyway, I got round this by making the small edit to the Ajax code as described then placing a conditional in the page code like so:

<?php
 $saved_pod_id = pods_sanitize($_GET['saved_pod_item']);
 $Record = new Pod('application_form',$saved_pod_id);
 if(is_numeric($saved_pod_id) && $Record->data) { 
   ?>
     Your application form has been received. blah blah... Thank you. 
  <? } else {
 $pods = new Pod('application_form'); 
 echo $pods->publicForm(); } 
 ?>

Not entirely sure if this is a good way to do this or not - but it does work :-) Looking forward to Pods2 when hopefully this stuff will be a bit easier/less hacky!

Cheers Mungo

answered Jan 4 '11 at 5:27

mungo

21

add comment
enter at least 15 characters
0

I would change the ajax code so that the redirect location is the current page like it's supposed to do, but add some arbitrary query to it so that you know the form has been submitted:

jQuery.ajax({
type: "post",
url: "<?php echo PODS_URL; ?>/ajax/api.php",
data: "action=save_pod_item&"+data.join("&"),
success: function(msg) {
    if ("Error" == msg.substr(0, 5)) {
        alert(msg);
    }
    else {
        window.location = "<?php echo $_SERVER['REQUEST_URI']; ?>"+"?saved_pod_item="+msg;
    }
    jQuery(".btn_save").attr("disabled", "");
} });

This actually passes a value of the pod item's 'tbl_row_id'. Then you can perform a check at the top of the form template page (before any output) that checks the existence of this parameter and whether the pod saved correctly, and redirect if it has been:

<?php

$saved_pod_id = pods_sanitize($_GET['saved_pod_item']); //get query parameter
$Record = new Pod('person',$saved_pod_id); //tries to create a pod with submitted tbl_row_id

if(is_numeric($saved_pod_id) && $Record->data) {  //redirect if Pod saved correctly
    wp_redirect(get_bloginfo('url').'/thanks');
}

?>

answered Jun 25 '10 at 11:36

clarinetlord

456

add comment
enter at least 15 characters
0

Thanks for this. My current template is made up of the following:

<?php
$Record = new Pod('member');
$fields = array('name', 'email');
echo $Record->publicForm($fields);
?>

Can you tell me where would I add the code you've mentioned above to this code in order for it all to work?

answered Jun 26 '10 at 6:38

daretothink

11

edited Jun 26 '10 at 6:39

add comment
enter at least 15 characters
0

Should work like this:

<?php
$saved_pod_id = pods_sanitize($_GET['saved_pod_item']);
$Record = new Pod('member',$saved_pod_id);
if(is_numeric($saved_pod_id) && $Record->data) {  
    wp_redirect(get_bloginfo('url').'/thanks');
}
$fields = array('name', 'email');
echo $Record->publicForm($fields);
?>

answered Jun 26 '10 at 8:50

clarinetlord

456

edited Jun 26 '10 at 8:51

add comment
enter at least 15 characters
0

Thanks again... Just added all of that and when I then submitted the public form - it added a new pod but the redirect didn't work and added this text above the form on the public form page:

Warning: Cannot modify header information - headers already sent by (output started at /home/intervie/public_html/wp-content/themes/centita/page.php:1) in /home/intervie/public_html/wp-includes/pluggable.php on line 868

Any ideas?

answered Jun 26 '10 at 9:23

daretothink

11

add comment
enter at least 15 characters
0

Like I said before, page redirects need to happen before ANY page output. Are you putting this code in a pod page, or a WP template file?

answered Jun 26 '10 at 10:22

clarinetlord

456

add comment
enter at least 15 characters
0

I'm calling a Pods template into a WP page by using the following shortcode:

[pods name="member" limit="1" template="member_addnew"]

Forgive me but I really am not all that confident with coding which is why I'm asking so many questions - sorry.

answered Jun 26 '10 at 11:21

daretothink

11

add comment
enter at least 15 characters