 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
sahand1010
Joined: 25 Apr 2008 Posts: 3
|
Posted: Tue Apr 29, 2008 8:19 pm Post subject: Quickform with Smarty Undefined index Error ?? |
|
|
I have setup QuickForm to be used with Smarty templates.
The form displays fine but below the form I get numerous Undefined index Errors.
| Quote: | ERRNO: 8
TEXT: Undefined index: form
LOCATION: /var/www/html/mysite/templates_c/%%ED^EDF^EDF8BD08%%example.tpl.php, line 51, at April 29, 2008, 10:59 am |
Am I calling the form correctly?
I am a newbie so please be patient. I would really like to learn how to use QF.
| Code: | require_once PEAR_DIR . 'HTML/QuickForm.php';
$form =& new HTML_QuickForm('exampleForm');
// delivery options
$form->addElement('radio', 'shipping', 'select a delivery method:', 'Best way shipping', 'bestway');
$form->addElement('radio', 'shipping', NULL, 'Will Call', 'willcall');
$form->addElement('radio', 'shipping', NULL, 'Delivery option', 'delivery');
$form->addElement('text', 'Number', 'number: ', array('size'=>20, 'maxlength'=>17));
$form->addElement('date','DATE','date: ',
array('format'=> 'M Y', 'addEmptyOption' => 'true', 'emptyOptionValue' => '', 'emptyOptionText' => '', 'minYear'=> date('Y'),'maxYear'=> date('Y')+10));
$form->addElement('text', 'Name', 'Your name:');
// submit
$form->addElement('submit', 'sended', 'continue');
// Filters: trim() function removes leading and trailing white spaces from data submitted
$form->applyFilter('__ALL__', 'trim');
// validation rules:
$form->addRule('shipping', 'Please select a shipping method.', 'required');
$form->addRule('Number', 'Please Enter Your Number.', 'required');
$form->addRule('Number', 'Please enter your correct number.', 'numeric');
$form->addRule('Number', 'Please enter your correct number.', 'minlength',15);
$form->addRule('date', 'Please enter your date.', 'required');
$form->addRule('Name', 'Please enter your name.', 'required');
$form->addRule('Name', 'Please enter your name.', 'minlength',3);
$form->addRule('Name', 'Please enter your name.', 'lettersonly');
// try to validate the form
if ($form->validate()) {
$form->freeze();
}
else
{
require_once(SMARTY_DIR . 'Smarty.class.php');
require_once PEAR_DIR . 'HTML/QuickForm/Renderer/ArraySmarty.php';
$tpl =& new Smarty();
$tpl->template_dir = TEMPLATE_DIR;
$tpl->compile_dir = COMPILE_DIR;
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$renderer->setRequiredTemplate(
'{strip}
{if $error}<img src="../images/warning.png" alt="Warning: {$error|strip_tags|escape}" /> {/if}
{$label}
{/strip}'
);
$renderer->setErrorTemplate('{$html}');
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
// render and display the template
$tpl->display('example.tpl');
} |
| Code: |
<form id="cc_shipping" method="post" action="">
<div class="boxContent">
<h3>Please enter your info:</h3>
<table>
<tr>
<td width="140">{$form.Number.label}</td>
<td>{$form.Number.html}</td>
</tr>
<tr>
<td width="140">{$form.date.label}</td>
<td>{$form.date.html}</td>
</tr>
<tr>
<td width="140">{$form.Name.label}</td>
<td>{$form.Name.html}</td>
</tr>
</table>
</div>
{$form.sended.html}
{* display an overview of all form errors *}
{foreach from=$form.errors item=error name=errorloop}
{if $smarty.foreach.errorloop.first}<ul class="warning">{/if}
<li>{$error}</li>
{if $smarty.foreach.errorloop.last}</ul>{/if}
{/foreach}
</form> |
*I am also using Smarty function Plugins. So, the template is called first and in return it loads the function.php file |
|
| Back to top |
|
 |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Wed Apr 30, 2008 2:08 pm Post subject: |
|
|
Hi,
maybe you could paste code from the template where the errors appear. |
|
| Back to top |
|
 |
sahand1010
Joined: 25 Apr 2008 Posts: 3
|
Posted: Wed Apr 30, 2008 9:55 pm Post subject: template code |
|
|
This is the entire template code. Once the page loads the form loads but below the form there are numerous Undefined index errors for the $form variable. The error is quoted above.
Thank you! I hope someone can help me with this.
| Code: |
{load_example assign="example"}
<div class="box">
<h2>Example page</h2>
<form id="example" method="post" action="">
<div class="boxContent">
<h3>Please enter your info:</h3>
<table>
<tr>
<td width="140">{$form.Number.label}</td>
<td>{$form.Number.html}</td>
</tr>
<tr>
<td width="140">{$form.date.label}</td>
<td>{$form.date.html}</td>
</tr>
<tr>
<td width="140">{$form.Name.label}</td>
<td>{$form.Name.html}</td>
</tr>
</table>
</div>
{$form.sended.html}
{* display an overview of all form errors *}
{foreach from=$form.errors item=error name=errorloop}
{if $smarty.foreach.errorloop.first}<ul class="warning">{/if}
<li>{$error}</li>
{if $smarty.foreach.errorloop.last}</ul>{/if}
{/foreach}
</form>
</div> |
|
|
| Back to top |
|
 |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Fri May 02, 2008 10:35 am Post subject: |
|
|
| I meant the compiled template |
|
| 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
|
|