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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

RequiredFields


Go to End


933 Views

Avatar
TDNP

Community Member, 19 Posts

5 January 2012 at 11:03am

Edited: 05/01/2012 11:04am

Before you say it, I've looked through the forums and haven't found why this would be happening.

$fields = new FieldSet(
new TextField('FirstName', 'First Name*'),
new TextField('LastName', 'Last Name*'),
new TextField('Business', 'Business Name'),
new TextField('Address', 'Full Address*'),
new TextField('Address2', 'Address Continued'),
new TextField('City', 'City'),
new TextField('State', 'State'),
new TextField('Zip', 'Zipcode'),
new NumericField('HomePhone', 'Home Phone* (No Dashes)', null, 9),
new NumericField('CellPhone', 'Cell Phone', null, 9),
new EmailField('Email', 'Email Address*')
);
// Create action
$actions = new FieldSet(
new FormAction('XMLWrite', 'Submit')
);

// Create validator
$validator = new RequiredFields('FirstName', 'LastName', 'Address', 'HomePhone', 'Email');

return new Form($this, 'DonationForm', $fields, $actions, $validator);

The form renders properly but the validation doesn't work. I can tab through the fields and submit the form without being required to enter any data. I don't want to write a validation script knowing that SS has one built in. Also, I have this working in a contact form on the same site. I've double and triple-checked my typing but after a while, my eyes get numb to reading the same code over and over. Can anyone offer a little help here?