CakePHP: How does a form still have your data in it when it doesn't validate? -
when create form element cakephp so:
echo $this->form->input('user.first_name');
you start blank field. when put in name john
, submit form, if form not validate, name john
still there when return page fix validation errors. convenient because can fix mistakes without having retype parts got right.
how put value?
i need know because once form submitted , leave page , come form blank again.
i saving name session can instead:
$first_name = $this->session->read('cart.user.first_name'); echo $this->form->input('user.first_name',array('value'=>$first_name));
now if lave page , come back, name still there breaks original logic preventing putting type in when form fails validate.
let me give example.
i creating name element like:
$first_name = $this->session->read('cart.user.first_name'); echo $this->form->input('user.first_name',array('value'=>$first_name));
i fill out form correctly , taken final checkout page. see misspelled name jhon
. clicked edit button , taken form, since manually set value
in form data still there. correctly retype name john
, submit form. other reason form did not validate , taken form, instead of displaying john
would, displays jhon
again because when manually set value
overriding default whatever still in session.
so if know how cakephp puts data in form when not validate, can put session data in same way without overriding default.
the data passed form in post data call. formhelper auto-magic elements use data populate value attributes of fields. if leave page, post information doesn't passed along.
you need save $this-data block in session value keep while moving page page.
Comments
Post a Comment