What is the best way to split up a "publicform" into multiple pages?
Hello folks!
I'm currently developing a club website. The club wants members to signup through a registration form that has 3 pages:
- Enter personal info
- Choose a city of club branch
- Enter bank info
My question is now: Is there a way to split the form generated with $this->publicForm?
All the best regards, Daniel
8 Answers
Just wanted to let you know how I solved my problem now. Here it is:
1.) Made a WP-Template to enclose the forms matching my layout
2.) Made a POD-Page for each form each form ends up with collection the values from the input fields added to the session. Sending form #1 and #2 via the <form action="next-form-number-xyz" ...>.
3.) On the last form page saving the collected values through: $api->save_pod_item($params);
thanks for standing by me and holding my hand guys! ;) keep coming your great works.
I'm not sure if this would work, but try creating three separate pages for the forms, where each page's "publicForm" call only shows the fields you want on that page. For example, the first page may have something this this:
<?php
$Record = new Pod('member');
$fields = array('name', 'address', 'email','phone');
echo $Record->publicForm($fields);
?>
Then, you need to connect each page to each other. The way "publicForm" saves its form is through an ajax call to PodAPI's method "save_pod_item", which in this case would only save partial pod information. However, if you add a post_save helper that instead of returning some sort of message in the ajax response, sends a javascript call to redirect to the next form page, adding the new pods id in the url so the next form page knows which pod item to save the rest of the info to:
<?php
$redirect_url = get_bloginfo('home').'/form-page-2/?id='.$params->tbl_row_id;
return '<script type="text/javascript">window.location="'.$redirect_url.'";</script>';
?>
Next, for the subsequent form pages, instantiate your Pod with the passed id of the new pod item:
<?php
$id = pods_url_variable('id','get');
$Record = new Pod('member',$id);
$fields = array('branch_state','branch_city', 'branch');
echo $Record->publicForm($fields);
?>
Lastly you would need to add something to that post-save helper that redirected to a thank you page if all the fields were completed:
<?php
if(empty($params->membership_confirmation)) { //check to see if the last form field has been set or not
$redirect_url = get_bloginfo('home').'/form-page-2/?id='.$params->tbl_row_id;
} else {
$redirect_url = get_bloginfo('home').'/form-thank-you/';
}
return '<script type="text/javascript">window.location="'.$redirect_url.'";</script>';
?>
I see that in the core code, you're correct. Instead, you'll have to save which form page should be loaded and the tbl_row_id as session variables. Try setting a session variable when the form page load. Then update that variable in your post_save helper to indicate that the form should proceed to the next page. Then when the page refreshes after saving, have the page check the value of the session variable and redirect to the next page if it's changed. Here's an example of what I'm talking about:
Top of all form pages:
<?php
session_start();
$form_page = 1; // this should be 1 for first page, 2 for second, etc.
if(isset($_SESSION['form_settings']) && $_SESSION['form_settings']['page'] != $form_page) {
//form settings exists and page number has changed, so redirect
$redirect_url = get_bloginfo('home').'/form-page-'.$_SESSION['form_settings']['page'];
header("Location: $redirect_url");
} else {
//initialize form settings
$_SESSION['form_settings'] = array('tbl_row_id'=>null,'page'=>$form_page);
}
$id = $_SESSION['form_settings']['tbl_row_id'];
$Record = new Pod('member', $id);
$fields = array('name', 'address', 'email','phone');
echo $Record->publicForm($fields);
?>
post_save helper:
<?php session_start(); $_SESSION['form_settings']['page']++; //increment page number for next form page $_SESSION['form_settings']['tbl_row_id'] = $params->tbl_row_id; // set id return true; ?>
edited Jun 20 '10 at 11:00
Okay that's worth a try... I'll give it one and brb.
edited Jun 18 '10 at 8:33
I just tried this way now, but I can't figure out to get the page being redirected after it has been saved once.
It seems that the problem is that i can't override the "window.location" that is loaded after a normal save. Because the core itself uses the "window.location" itself before i can override.
Maybe someone knows how to override the window.location here in the userguide community. I'll appreciate your help guys. thanks in advance.
Hi clarinetlord,
I tried it this way, but the page still won't redirect. Also I came across some security mess if I would handle a membership registration this way:
If every user could edit and view an entry through a publicform by guessing an ID/number it could be some sort of offending data privacy... what do you think?
I'm now going to make a simple form (of course splitted into 3 pod pages) which will be resulting into one sigle save action.
So no editing after a partial save or some sort of that. Although I hope that I can make this last single save action into the pods data environment to use the beautiful features of the "pods ui"-plugin for editing datasets in the backend.
Works fine now: http://www.lohnsteuerhilfe.net/mitglied-werden


