How can you code an element NOT to go through the
element renderer, whether its default or custom?
To be honest, I don't know. I use QuickForm + SmartyArray renderer so that I can do all of the programming and then pass it on the to designer to build the templates. Sure, it means more work, but the plus is, you have complete control over the form styling and a separation between logic and view.
Sample form (NOT TESTED):
<?php
// Include the QuickForm class
require_once ('HTML/QuickForm.php');
// Include the QuickForm Smarty Renderer
require_once ('HTML/QuickForm/Renderer/ArraySmarty.php');
// Include PHPMailer class
require_once ('/path/to/phpmailer/class.phpmailer.php');
// Require Smarty
require_once('/path/to/smarty/Smarty.class.php');
$tpl =& new Smarty;
$tpl->template_dir = '/path/to/smarty/templates/';
$tpl->compile_dir = '/tmp';
$form = new HTML_QuickForm('myform', 'post');
$form_result = $form->getSubmitValues();
$form->addElement('text','Name','Name:');
$form->addRule('Name','Please provide your Name:','required',false);
$form->addElement('text','Email','Email Address:');
$form->addRule('Email','Please provide your Email Address:','required',false);
$form->addRule('Email','Please provide a valid Email Address:','email',false);
$form->addElement('reset','reset','Reset');
$form->addElement('submit','submit','Submit');
$form->setRequiredNote('<span class="required">*</span> This indicates a required field.');
if (!$form->validate()) {
// Display initial page view
// Create the renderer object
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$renderer->setErrorTemplate('{if $error}<span class="error">{$error}</span><br />{/if}{$html}');
$renderer->setRequiredTemplate('{$label} {if $required}<span class="required">*</span>{/if}');
// build the HTML for the form
$form->accept($renderer);
// assign array with form data
$tpl->assign('form_data', $renderer->toArray());
$tpl->assign('pagetitle', 'Enter your personal details - We won\'t use it for anything illegal, promise...');
$tpl->display('mailform.tpl');
} else {
// Display submitted page view
// Create the renderer object
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$renderer->setRequiredTemplate('{$label} {if $required}<span class="required">*</span>{/if}');
// build the HTML for the form
$form->accept($renderer);
// assign array with form data
$tpl->assign('form_data', $renderer->toArray());
$msg = 'Test message';
$mail->IsHTML(true);
$mail->Mailer = 'smtp';
$mail->FromName = $form_result['Name'];
$mail->From = $form_result['Email'];
$mail->AddAddress($Toemail,$Toname);
$mail->Subject = 'User Details';
$mail->Body = $msg;
if ( !$mail->Send() ) {
$tpl->assign('display', '<div class="success"><p><span class="error">Oops! There was an error sending your request. Try again?</span></p></div>');
$tpl->assign('pagetitle', 'Oops! - There was an error...');
$tpl->display('mailform-error.tpl');
} else {
header("Location: http://www.example.com/thanks/");
}
}
?>
Those form elements are now available in the Smarty templates as:
{if $display}
{$display}
{/if}
<label>
{$form_data.firstname.label}<br />
{$form_data.firstname.html}</label>
<label>
{$form_data.lastname.label}<br />
{$form_data.lastname.html}</label>
{$form_data.reset.html} {$form_data.submit.html}
Of course, you could set an element template in Smarty and use that for every element, but for my purposes, this way works just fine. Sorry I can't be more helpful, I hope that gives you some options/ideas.
Cheers;
Poncho
On 24 Aug 2005, at 14:10, l Burnerheimerton wrote:
I thought every element had to go through a renderer.
How can you code an element NOT to go through the
element renderer, whether its default or custom?
--- Poncho Pilate <poncho@zoom.co.uk> wrote:
I could be talking complete garbage here, but I'll
try to help.
If the form is of a reasonable size, I would set up
an array of
single elements you want to add a <label> for, then
do a foreach on
that array passing each element name to QuickForms
'setElementTemplate' function. Then do the same for
element groups
that cannot have a <label>.
Try this:
$LabelStyle = '<label class="formT">{label}<!--
BEGIN required
--><span>*</span><!-- END required --></label>
<!-- BEGIN error --><span
style=>{error}</span><br/><!-- END error
-->{element}<br/>';
$PlainStyle = '{label}<!-- BEGIN required
--><span>*</span><!-- END required -->
<!-- BEGIN error --><span
style=>{error}</span><br/><!-- END error
-->{element}<br/>';
$SingleElements =
array('firstname','lastname','email');
$GroupElements =
array('radios1','advcheckboxes','date');
foreach ($SingleElements as $ElementName) {
$form->setElementTemplate($LabelStyle,$ElementName);
}
foreach ($GroupElements as $ElementName) {
$form->setElementTemplate($PlainStyle,$ElementName);
}
I haven't tested this, but I think it will work :-)
Cheers;
Poncho
On 24 Aug 2005, at 13:09, l Burnerheimerton wrote:
Poncho
I read your post about not wrapping around certain
elements. How do you determine which elements
will be
wrapped?
Thanks
____________________________________________________
Start your day with Yahoo! - make it your home
page
http://www.yahoo.com/r/hs
--PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit:
http://www.php.net/unsub.php
--PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
--PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php