For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > January 2007 > Displaying Quickform validation errors with ITStatic renderer









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Displaying Quickform validation errors with ITStatic renderer
John

2007-01-29, 7:00 pm

Hi

I am trying to get a validation error message appear at the top of my
form but they always appear in a separate window. I am using the
examples from the Pear site. I must be doing something very silly!

Any pointers would be very welcome.

Thank you

John


<?php
require_once ("HTML/QuickForm.php");

$form = new HTML_QuickForm('myform', 'POST');
$form->addElement('header', 'myheader', 'Registration form');

$form->addElement('hidden', 'session', '123456');

$name['last'] = &HTML_QuickForm::createElement('text', 'first', 'First',
array('size' => 10));
$name['first'] = &HTML_QuickForm::createElement('text', 'last', 'Last',
array('size' => 10));
$form->addGroup($name, 'name', 'Name:', '-');

$form->addElement('text', 'email', 'Your email:');

$select = array('' => 'Please select...',
'AU' => 'Australia',
'FR' => 'France',
'DE' => 'Germany',
'IT' => 'Italy');
$form->addElement('select', 'country', 'Country:', $select);

$form->addElement('reset', 'reset', 'Reset');
$form->addElement('submit', 'submit', 'Register');

$form->addElement('checkbox', 'news', '', " Check this box if you don't
want to receive our newsletter.");

$form->addRule('email','Enter email','required','null','client');



require_once 'HTML/Template/Sigma.php';
require_once 'HTML/QuickForm/Renderer/ITStatic.php';

$tpl =& new HTML_Template_Sigma('.');
$tpl->loadTemplateFile('test.htm'); // or whatever you called it

$renderer =& new HTML_QuickForm_Renderer_ITStatic($tpl);
$renderer->setRequiredTemplate('{label}<font color="red"
size="1">*</font>');
$renderer->setErrorTemplate('<font
color="red">{error}</font><br />{html}');
$form->validate();
$form->accept($renderer);
$tpl->show();
?>

AND
<html>
<head><title>My Form</title>
{myform_javascript}
</head>
<body>
<form {myform_attributes}>
{myform_session_html}
<!-- BEGIN myform_error_loop -->
<font color="red">{myform_error}</font><br />
<!-- END myform_error_loop -->


<table>
<tr><th colspan="2">{myform_myheader}</th></tr>

<tr><td>{myform_name_first_html}</td><td>{myform_name_last_html}</td></tr>

<tr><td>{myform_name_first_label}</td><td>{myform_name_last_label}</td></tr>

<tr><td>{myform_email_label}</td><td>{myform_email_html}</td></tr>
<tr><td>{myform_country_label}</td><td>{myform_country_html}</td></tr>
<tr><td colspan="2" align="right">{myform_reset_html}
{myform_submit_html}</td></tr>
</table>
<br /><br />
{myform_news_html}
</form>
</body>
</html>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com