|
|||
|
POST shows nothing when in 'edit'
but when you submit and back at 'controller/phone' (the rest of the values in the url are left off since it's just showing itself now.) POST: Array ( [pnum] => 9735551212 [cc] => [numtype] => C [Submit] => Submit [id] => 1 ) SANITIZED (when placed just inside the (isPost) check and before (isValid): Array ( [pnum] => [cc] => [numtype] => ) |
|
|||
|
To get here, links look like:
/user/phone/number/edit/id/2 or /user/phone/number/new Here is the entire action and form: Code:
public function getPhoneForm() {
if (null === $this->_form) {
$this->_form = new User_PhoneNumbersForm(array(
'action' => '/personnel/phone',
'method' => 'post',
));
}
return $this->_form;
}
public function phoneAction() {
$this->_helper->layout->disableLayout();
// get the form and save to a view var
$this->view->form = $this->getform();
$params = $this->_request->getParams();
// check if the form was submitted via post
if ($this->_request->isPost()) {
print_r($_POST);
$sanitizedValues = $this->view->form->getValues();
if (isset($sanitizedValues['id'])) {
$this->view->form->addPhoneRecID($sanitizedValues['id']);
}
if ($this->view->form->isValid($this->_request->getPost())) {
// the form is valid, save to db via a method within this controller
} else {
// the form is not valid, send the user back to the form with a message generated by Zend_Form
}
} else {
switch ($params['number'])
{
case 'new':
break;
case 'edit':
$this->view->form->addPhoneRecID($params['id']);
$this->view->form->populate($this->getNumberInfo($params['id']));
break;
default:
}
}
}
class User_PhoneNumbersForm extends Our_Form {
public $numbers = array();
public $number_field_options = array(
'W' => 'Work',
'H' => 'Home',
'C' => 'Cell'
);
public function __construct($options = null) {
parent::__construct($options);
$this->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
array('Description', array('placement' => 'prepend')),
'Form'
));
}
public function init()
{
$this->addElement('text', 'pnum', array(
'filters' => array('StringTrim', 'StringToLower'),
'validators' => array(
array('regex',true, array('/^[0-9.()]{7,20}$/i')),
array('StringLength', true, array(7, 20)),
),
'required' => true,
'label' => 'Phone Number:',
'class' => 'text'
));
$this->addElement('text', 'cc', array(
'filters' => array('StringTrim', 'StringToLower'),
'validators' => array(
'Digits',
array('StringLength', true, array(1, 4)),
),
'required' => true,
'label' => 'Country Code:',
'class' => 'text'
));
$this->addElement('select', 'numtype', array(
'label' => 'Type',
'isArray' => false,
'multiOptions' => $this->number_field_options
) );
$this->addDisplayGroup(
array('pnum', 'cc', 'numtype'),
'phonenumbers',
array(
'disableLoadDefaultDecorators' => true,
'decorators' => $this->_standardGroupDecorator,
'legend' => 'Add New Number:',
)
);
$updateinfo = $this->addElement('submit', 'Submit', array(
'required' => false,
'ignore' => true,
'label' => 'Submit',
'class' => 'button'
));
}
public function addPhoneRecID($val) {
$this->addElement('hidden', 'id', array(
'filters' => array('StringTrim'),
'validators' => array(
'Digits',
array('Between',true, array(1,20))
),
'value' => $val,
'required' => true
));
}
}
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|