 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
Mindstar
Joined: 01 May 2008 Posts: 5 Location: UK
|
Posted: Sat May 03, 2008 2:47 pm Post subject: Trying to create a confirmation page with Quickform |
|
|
Hi, I'm trying to add a confirmation screen to a "Contact Us" Quickform.
I have built a "Contact Us" forum using Quickform which works perfectly - kudos to the developers
I am now struggling to figure out the best way to add a confirmation screen which pretty-prints the information that the user submitted on the previous screen and gives the user two options:
[Go Back] to the original screen to re-edit the form using the information that they have just submitted
or
[OK] to send the message.
So far I've experimented with creating a second quickform object and using that to display the submitted information and the [Go Back] and [OK] buttons, but am running into problems revalidating their input which I've used as the default values for the form.
I am using a PHP Session to pass the submitted information back and forth between these two forms via the exportValues() method.
I've had a look at the QF Controller, but that breaks the "embedability" of the QuickForm in a page as QFC uses header: to set which page the form is on  |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Sat May 03, 2008 6:23 pm Post subject: Re: Trying to create a confirmation page with Quickform |
|
|
| Mindstar wrote: | I've had a look at the QF Controller, but that breaks the "embedability" of the QuickForm in a page as QFC uses header: to set which page the form is on  |
I would have recommended QFC, too. Can you please elaborate about the problems you see? In general, this should work.
Having two normal QF forms would also work, as you're already keeping the data in the session. On the second "page", you could freeze all fields before you display the form. |
|
| Back to top |
|
 |
Mindstar
Joined: 01 May 2008 Posts: 5 Location: UK
|
Posted: Sun May 04, 2008 12:52 pm Post subject: Re: Trying to create a confirmation page with Quickform |
|
|
| mark wrote: | | Mindstar wrote: | I've had a look at the QF Controller, but that breaks the "embedability" of the QuickForm in a page as QFC uses header: to set which page the form is on  |
I would have recommended QFC, too. Can you please elaborate about the problems you see? In general, this should work. |
I am using a Dreamweaver Template to build/manage the website design and structure, so I was hoping to be able to embed the Form into the body of page without having to mess around with defining a header and footer within QFC.
| mark wrote: |
Having two normal QF forms would also work, as you're already keeping the data in the session. On the second "page", you could freeze all fields before you display the form. |
OK. It sounds like I'm on the right track with this approach, as I can embed this in a Dreamweaver Templated page.
Thanks. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Sun May 04, 2008 2:11 pm Post subject: Re: Trying to create a confirmation page with Quickform |
|
|
| Mindstar wrote: | | mark wrote: | | Mindstar wrote: | I've had a look at the QF Controller, but that breaks the "embedability" of the QuickForm in a page as QFC uses header: to set which page the form is on  |
I would have recommended QFC, too. Can you please elaborate about the problems you see? In general, this should work. |
I am using a Dreamweaver Template to build/manage the website design and structure, so I was hoping to be able to embed the Form into the body of page without having to mess around with defining a header and footer within QFC. |
I'm still unsure about what problems you see here. QFC is just an extension to QF. Outputting a QFC form should be as easy as a QF form. |
|
| Back to top |
|
 |
Mindstar
Joined: 01 May 2008 Posts: 5 Location: UK
|
Posted: Sun May 04, 2008 4:02 pm Post subject: |
|
|
I get this error
| Quote: | | Warning: Cannot modify header information - headers already sent by (output started at F:\Eclipse Workspace\MSG Forms\qfc-test.php:135) in C:\xampp\php\PEAR\HTML\QuickForm\Action\Jump.php on line 60 |
with this code - it is the QFC wizard.php example with some HTML wrapped around wizard->run()
QFC appears to be issuing a redirect via the header location: paramater, which breaks the way that I want to embed the QFC in my webpage.
| Code: |
<?php
/**
* Example 2 for HTML_QuickForm_Controller: Wizard
*
* @version CVS: $Id: wizard.php,v 1.3 2007/05/18 09:34:18 avb Exp $
* @author Alexey Borzov <avb@php.net>
* @ignore
*/
require_once 'HTML/QuickForm/Controller.php';
// Load some default action handlers
require_once 'HTML/QuickForm/Action/Next.php';
require_once 'HTML/QuickForm/Action/Back.php';
require_once 'HTML/QuickForm/Action/Jump.php';
require_once 'HTML/QuickForm/Action/Display.php';
require_once 'HTML/QuickForm/Renderer/Tableless.php';
// Start the session, form-page values will be kept there
session_start();
class Tableless_Display extends HTML_QuickForm_Action_Display
{
function _renderForm(&$page)
{
$renderer =& new HTML_QuickForm_Renderer_Tableless();
$page->accept($renderer);
echo $renderer->toHtml();
}
}
class PageFirst extends HTML_QuickForm_Page
{
function buildForm()
{
$this->_formBuilt = true;
$this->addElement('header', null, 'Wizard page 1 of 3');
$radio[] = &$this->createElement('radio', null, null, 'Yes', 'Y');
$radio[] = &$this->createElement('radio', null, null, 'No', 'N');
$this->addGroup($radio, 'iradYesNo', 'Are you absolutely sure?');
$this->addElement('submit', $this->getButtonName('next'), 'Next >>');
$this->addRule('iradYesNo', 'Check Yes or No', 'required');
$this->setDefaultAction('next');
}
}
class PageSecond extends HTML_QuickForm_Page
{
function buildForm()
{
$this->_formBuilt = true;
$this->addElement('header', null, 'Wizard page 2 of 3');
$name['last'] = &$this->createElement('text', 'last', null, array('size' => 30));
$name['first'] = &$this->createElement('text', 'first', null, array('size' => 20));
$this->addGroup($name, 'name', 'Name (last, first):', ', ');
$prevnext[] =& $this->createElement('submit', $this->getButtonName('back'), '<< Back');
$prevnext[] =& $this->createElement('submit', $this->getButtonName('next'), 'Next >>');
$this->addGroup($prevnext, null, '', ' ', false);
$this->addGroupRule('name', array('last' => array(array('Last name is required', 'required'))));
$this->setDefaultAction('next');
}
}
class PageThird extends HTML_QuickForm_Page
{
function buildForm()
{
$this->_formBuilt = true;
$this->addElement('header', null, 'Wizard page 3 of 3');
$this->addElement('textarea', 'itxaTest', 'Parting words:', array('rows' => 5, 'cols' => 40));
$prevnext[] =& $this->createElement('submit', $this->getButtonName('back'), '<< Back');
$prevnext[] =& $this->createElement('submit', $this->getButtonName('next'), 'Finish');
$this->addGroup($prevnext, null, '', ' ', false);
$this->addRule('itxaTest', 'Say something!', 'required');
$this->setDefaultAction('next');
}
}
class ActionProcess extends HTML_QuickForm_Action
{
function perform(&$page, $actionName)
{
echo "Submit successful!<br>\n<pre>\n";
var_dump($page->controller->exportValues());
echo "\n</pre>\n";
}
}
$wizard =& new HTML_QuickForm_Controller('Wizard');
$wizard->addPage(new PageFirst('page1'));
$wizard->addPage(new PageSecond('page2'));
$wizard->addPage(new PageThird('page3'));
// We actually add these handlers here for the sake of example
// They can be automatically loaded and added by the controller
// $wizard->addAction('display', new HTML_QuickForm_Action_Display());
// Use the Tabless_Display class to draw the pages.
$wizard->addAction('display', new Tableless_Display());
$wizard->addAction('next', new HTML_QuickForm_Action_Next());
$wizard->addAction('back', new HTML_QuickForm_Action_Back());
$wizard->addAction('jump', new HTML_QuickForm_Action_Jump());
// This is the action we should always define ourselves
$wizard->addAction('process', new ActionProcess());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP QuickForm Test</title>
<link href="quickform.css" rel="stylesheet" media="screen, projection" type="text/css" />
</head>
<body>
<div id="content" style="width: 800px; margin: 0px auto; padding: 0 20px; background-color: #eef;">
<h1>PHP QuickForm Test</h1>
<?php $wizard->run(); ?>
</div>
</body>
</html>
|
|
|
| Back to top |
|
 |
beowulf2128
Joined: 21 Jun 2008 Posts: 1
|
Posted: Sat Jun 21, 2008 10:09 pm Post subject: My solution for a confirmation page |
|
|
I built a form manager for my business using HTML_Quickform that included a confirmation screen (preview the form submission) and did not use QFC or multiple quickform objects.
I extended the HTML_Quickfrom class with my own form_manager class and overwrote the process() function to test for what kind of form submission had just occurred.
| Code: |
function process ($validate = true) {
# form submission
if ((! $validate) || $this->validate()) {
# Edit user input - go back to original form with fields filled in
if ($_POST['confirmedit'] == "Edit") {
$this->display();
# Show user input - confirm that the user entered what they meant to enter
} elseif ($_POST['submit']) {
$this->addConfirmMsg("Please click \"Confirm\" to complete the submission. To make changes, click \"Edit.\"");
$this->removeElement('submit');
$buttons[] = &HTML_QuickForm::createElement('submit', null, 'Confirm', array("style"=>"width: 85px;"));
$buttons[] = &HTML_QuickForm::createElement('submit', null, 'Edit', array("style"=>"width: 85px;"));
$this->addGroup($buttons, 'confirmedit', null, ' ');
$this->displayPreview();
# Submission confirmed - write to DB (,send emails), show status msg
} elseif ($_POST['confirmedit'] == "Confirm") {
//Submission confirmed. Write to DB or send emails etc
// ...
}
}
}
# Function: previewSubmission()
# Displays user input for confirmation (user input saved in hidden fields)
function displayPreview() {
$this->freeze();
$this->display();
}
|
|
|
| Back to top |
|
 |
Mindstar
Joined: 01 May 2008 Posts: 5 Location: UK
|
Posted: Mon Jun 23, 2008 11:52 am Post subject: |
|
|
Hi beowulf2128
thanks for the sample code. I'll have a look at that and see if I can get it working on my form - I'd given up on the confirmation screen  |
|
| Back to top |
|
 |
Mindstar
Joined: 01 May 2008 Posts: 5 Location: UK
|
Posted: Tue Jun 24, 2008 5:49 pm Post subject: |
|
|
Yippeee! I got it working
Didn't need to overload HTML_Quickform process function, I just adapted your example code slightly and added it to the section of code that calls the QuickForm output (rendering).
| Code: |
##
## put your code to create QuickForm Elements, Rules & Filters here
##
if ($form->validate()) {
# Edit user input - go back to original form with fields filled in
if ($_POST['confirmedit'] == "Edit") {
$form->accept($renderer);
echo $renderer->toHtml();
} elseif ($_POST['submit']) {
// show the user the confirmation screen, with the option to go back and edit their information
$form->removeElement('submit');
$buttons[] = &HTML_QuickForm::createElement('submit', null, 'Confirm', array("style"=>"width: 85px;"));
$buttons[] = &HTML_QuickForm::createElement('submit', null, 'Edit', array("style"=>"width: 85px;"));
$form->addGroup($buttons, 'confirmedit', null, ' ');
$form->freeze();
$form->accept($renderer);
echo $renderer->toHtml();
# Submission confirmed - write to DB (,send emails), show status msg
} elseif ($_POST['confirmedit'] == "Confirm") {
// Submission confirmed. Write to DB or send emails etc
$form->process("msg_sendmail", true);
}
} else {
$form->accept($renderer);
echo $renderer->toHtml();
}
|
Many thanks for making the effort to register and share your code!
* I am using the DHTMLRulesTableless version of QuickForm, so the following PHP code is used to produce the QuickForm HTML & Clientside Javascript Code
| Code: |
$form->accept($renderer);
echo $renderer->toHtml();
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|