liamC
Member
Registered: 28th Feb 04
User status: Offline
|
Have a contact form with the usual shit "Name", "Email Address", "Tel No", etc.
One of the options is a drop down box with the following 2 options:
"Personal Enquiry"
"Business Enquiry"
If the user chooses the "Personal Enquiry" option, then I want to make the "Fax No" and "No. of Employees" text fields non-mandatory.
Currently all fields are mandatory, and come up with a validation error if the user does not enter anything into the box, but obviously for a Personal Enquiry the 2 aforementioned fields aren't necessary.
Any ideas how this is achievable?
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
What does the validation look like?
|
DaveyLC
Member
Registered: 8th Oct 08
Location: Berkshire
User status: Offline
|
Its better to do the validation in javascript in the forms on submit event, that way you dont have to refresh the page.
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
You still want validation at server level though. I wouldn't trust javascript to validate anything going into a database.
|
AndyKent
Member
Registered: 3rd Sep 05
User status: Offline
|
Two options, make the two fields non-mandatory and throw an error in your script if the user fails to fill them in when they should, or make your code enter a random value in the fields just to fill the space.
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
On the option box, use the onchange to enable false/true the Fax number and no of employees. Then regex the fields, probably on the submit, as required.
Obviously you want to double check everything php/server side before dumping it to the DB but that'd be the easiest way of doing it.
|
liamC
Member
Registered: 28th Feb 04
User status: Offline
|
Got it working due to Javascript thanks to this: http://www.sitepoint.com/forums/printthread.php?t=319080&pp=25
|