The Solar_Sql_Model_Record::newForm() method builds the form object for you automatically, but eventually you will want to modify or customize that form object (e.g., to change the textarea attributes).
First, you can tell the newForm()
method which
record properties you want in the form. For example, let's have our
page-controller action method only get a form of the record's
name
properties.
<?php
/**
* @var Acme_Model_Users_Record $this->item A record object.
*/
$this->form = $this->item->newForm(array(
'name_first',
'name_middle',
'name_last',
));
We can also override the form element descriptors. For example, let's
limit the name_middle
element to 3 characters wide
in the form.
<?php
/**
* @var Acme_Model_Users_Record $this->item A record object.
*/
$this->form = $this->item->newForm(array(
'name_first',
'name_middle' => array(
'attribs' => array(
'size' => 3,
)
),
'name_last',
));
However, instead of doing that in the controller logic, it's usually
better to override the newForm()
method and
modify the form object before returning it. That way, any logic that
needs a form object can use the record method, instead of
re-customizing the form every time.
We can also create extra methods on the record object for the specific
kinds of forms we need. These methods can themselves use
newForm()
internally to do most of the heavy
lifting. For example:
<?php
class Acme_Model_Users_Record
{
public function newFormOfNames()
{
$form = $this->newForm(array(
'name_first',
'name_middle' => array(
'attribs' => array(
'size' => 3,
)
),
'name_last',
));
return $form;
}
}