How to force people to fill out "comments" ?

Small piece of code below - the required fields section is fine, but doesn’t work for the comments field?

[php]

<?php if(isset($_POST['submit'])) { $name = $_POST['name']; // required $telephone_number = $_POST['telephonenumber']; // required $email_address = $_POST['emailaddress']; // required $email_address_confirm = $_POST['emailaddressconfirm']; // required $person_or_company = $_POST['personorcompany']; // required //A: 1st field corresponds to last field of C (below) - 2nd fields are html names $comments = $_POST['comments']; // required $interest = $_POST['interest']; // required $how_find = $_POST['source']; $termsagreed = $_POST['termsagreed']; // required if(!isset($_POST['name']) || $_POST['name']=='' || !isset($_POST['telephonenumber']) || $_POST['telephonenumber']=='' || // correspond to html names - these are the required fields !isset($_POST['emailaddress']) || $_POST['emailaddress']=='' || !isset($_POST['emailaddressconfirm']) || $_POST['emailaddressconfirm']=='' || !isset($_POST['personorcompany']) || $_POST['personorcompany']=='' || !isset($_POST['interest']) || $_POST['interest']=='' || !isset($_POST['comments']) || $_POST['comments']=='' || !isset($_POST['termsagreed']) || $_POST['termsagreed']==''){ die('You have not filled in all of the required fields - please hit your back button and try again!'); } [/php]

seems you have tested the $_POST[‘comments’] twice…try to remove the other one and it should work.

If you’re getting the same problem, check your form if there’s such text field named ‘comments’…you might have some sort of typo error.

If you can’t make it work, try to perform client-side form validation using javascript. This way you can reduce server load…

Cheers.

Sorry, I’ve no idea what you mean - the “comments” fields are exactly the same as the other - working - mandatory fields to my eye?

Hi beelz,

Would you mind post your form code here?

Sure, here’s the html.

Contact us today


Name or Company Name*
Email Address*
Confirm Email Address
Telephone Number*
Please give us some further information

Which of the following is of interest?*

Web Design Logo Design Copy Writing

Other (please add comments)

Please add any further comments/information below:


Where did you hear about us?

Choose Option Google Other Search Engine Facebook Facebook Advertisement Online Advertisement Card/Flyer or Print Advertisement Word of Mouth Other (please state in comments)

Hi beelz,

Try this:
[php]

<?php $name=$_POST['name']; $telephone_number=$_POST['telephonenumber']; $email_address=$_POST['emailaddress']; //$person_or_company=$_POST['personorcompany']; $comments=$_POST['comments']; $interest=$_POST['interest']; //$how_find=$_POST['source']; //$termsagreed=$_POST['termsagreed']; if($name=='' || $telephone_number=='' || $email_address=='' || $interest=='' || $comments=='') { die('Some required fields missing'); } else{ echo "inputs are ok"; } ?>

[/php]

Notice I excluded some fields during testing coz we’re only interested to the required fields namely: $name, $telephone_number, $email_address, $interest, and $comments.

You can preview it here http://freddielore.110mb.com/phphelp/form.html

Thanks, but nope - still the same - the comment section is still not acting as a mandatory field…

Any more ideas people? It must be something sooooo simple…

RESOLVED - thanks all.

Sponsor our Newsletter | Privacy Policy | Terms of Service