corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Coding - Contact Form "IF" Statements


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP Coding - Contact Form "IF" Statements
liamC
Member

Registered: 28th Feb 04
User status: Offline
1st Sep 09 at 11:53   View User's Profile U2U Member Reply With Quote

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
1st Sep 09 at 12:08   View User's Profile U2U Member Reply With Quote

What does the validation look like?
DaveyLC
Member

Registered: 8th Oct 08
Location: Berkshire
User status: Offline
1st Sep 09 at 12:09   View User's Profile U2U Member Reply With Quote

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
1st Sep 09 at 12:18   View User's Profile U2U Member Reply With Quote

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
1st Sep 09 at 12:23   View User's Profile U2U Member Reply With Quote

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
1st Sep 09 at 13:03   View User's Profile U2U Member Reply With Quote

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
1st Sep 09 at 13:08   View User's Profile U2U Member Reply With Quote

Got it working due to Javascript thanks to this: http://www.sitepoint.com/forums/printthread.php?t=319080&pp=25

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
WORST DAY OF MY LIFE T2NY X General Chat 31 1869
5th Aug 03 at 22:33
by T2NY X
 
forum hacking - SQL's Drew Geek Day 15 1720
9th Sep 04 at 23:50
by Ian
 
Delphi - Errors Jamie General Chat 4 141
15th Sep 04 at 15:37
by PaulW
 
Anyone know PHP? Bit of help needed... liamC Geek Day 38 1455
24th Nov 06 at 23:02
by MarkPW
 
php and mysql help please bigD21 Geek Day 4 431
30th Aug 08 at 16:46
by bigD21
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Coding - Contact Form "IF" Statements 29 database queries in 0.0102429 seconds