
Untitled
By: a guest on
Jun 13th, 2012 | syntax:
PHP | size: 1.11 KB | hits: 9 | expires: Never
//getting the form
$name = new Element('name');
$name->setAttributes(array('type' => 'text', 'label' => 'Your name'));
$form = new Form('contact');
$form->add($name);
// than I return the form to view
public function indexAction ()
{
return new ViewModel(array('form' => $this->getForm()));
}
//in view
<?php
// within a view script
$form = $this->form;
$form->prepare();
// Assuming the "contact/process" route exists...
$form->setAttribute('action', 'contact/process');
// Set the method attribute for the form
$form->setAttribute('method', 'post');
// Render the opening tag
echo $this->form()->openTag($form);
?>
<div class="form_element">
<?php
$name = $form->get('name');
echo $this->formLabel()->openTag($name);
echo $this->formInput($name);
echo $this->formElementErrors($name);
echo $this->formLabel()->closeTag();
?></div>
// i expect the "formLabel" to echo the label. It does. But the label is empty - the "Your name" is missing.
//SOLVED - I need to echo the label myself:
echo $this->escape($name->getAttribute('label'));
// FFffffffffuuuuuuuuu