Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Custom Form Loses values after validation

Go to End



Community Member, 8 Posts

20 September 2012 at 9:05pm

I have a custom order form that does everything okay except when one of the required fields is not entered and the validation kicks in, I lose the values from all the other fields. My form fields are created like so:

new TextField('Company','Company'),
new TextField('Contact', 'Contact'),
new TextareaField('Company_Address', 'Company Address'),

And the form is constructed the following way:
$requiredFields[] = 'Company';
$actions = new FieldSet(new FormAction('processOrder', _t('OrderForm.PROCESSORDER','Place order')));
$validator = new OrderForm_Validator($requiredFields);
parent::__construct($controller, $name, $fields, $actions, $validator);
if($this->extend('updateFields', $fields) !== null) {$this->setFields($fields);}
if($this->extend('updateActions', $actions) !== null) {$this->setActions($actions);}
if($this->extend('updateValidator', $validator) !== null) {$this->setValidator($validator);}

I have tried removing the lines from the form action script that clears the session data, but that has not helped.
It seems that the javascript validation does not actually kick in and it gets validated server side, but not sure how to make the javascript validation kick in.

Any help would be great!