Hi,
I am fairly new silverstripe and I need to validate a form depending on the state of another form.
My first form is a shopping basket with 2 delivery option( 'free' or 'not free').
My second form is a set of delivery address details. Some of the fields are for the 'free' option. The other fields are for the 'not free' option. I can change the visibility of the fields using Jquery. That seems to be working.
My issue comes when validating the form. How can I tell silverstripe which fields are compulsory and which are not?
Currently I have:
new FieldList(
$TradeName = new TextField('Name', 'Name'),
$TradeCompanyName = new TextField('CompanyName', 'Company Name'),
$TradeEmail = new EmailField('Email', 'Email Address'),
$TradePhone = new TextField('Phone', 'Telephone Number'),
$TradeAddress1 = new TextField('Address1', 'Delivery Address Line 1'),
$TradeAddress2 = new TextField('Address2', 'Delivery Address Line 2'),
$TradeCity = new TextField('City', 'Delivery Town/City'),
$TradePostcode = new TextField('Postcode', 'Delivery Postcode'),
$TradeNotes = new TextareaField('Notes', 'Order Notes'),
$CustomerName = new TextField('CustomerName', 'Customer Name'),
$CustomerEmail = new EmailField('CustomerEmail', 'Email Address'),
$CustomerPhone = new TextField('CustomerPhone', 'Telephone Number'),
$CustomerAddress1 = new TextField('CustomerAddress1', 'Delivery Address Line 1'),
$CustomerAddress2 = new TextField('CustomerAddress2', 'Delivery Address Line 2'),
$CustomerCity = new TextField('CustomerCity', 'Delivery City'),
$CustomerPostcode = new TextField('CustomerPostcode', 'Delivery Postcode'),
$CustomerNotes = new TextField('CustomerNotes', 'Order Notes'),
new FormValidator(array(
'Name' => array('required'),
'Email' => array('required'),
'Phone' => array('required'),
'Address1' => array('required'),
'City' => array('required'),
'Postcode' => array('required'),
'CustomerName' => array('required'),
'CustomerEmail' => array('required'),
'CustomerPhone' => array('required'),
'CustomerAddress1' => array('required'),
'CustomerCity' => array('required'),
'CustomerPostcode' => array('required')
))
but I must have to add something as this depends on the delivery option. just don't know what it is...
As an laternative to Silverstripe validation, I am thinking of using jquery validation [url= https://jqueryvalidation.org/] [url]https://jqueryvalidation.org/ . Would that be better?