Making HTML form fields required

I know this will be easy for most of you, but I’m just now getting my first CGI formmail script up & running (finally).

I need to know how to rig things in my form to where each field I put on the form has to be filled in.

I know there’s a way to do this after seeing other forms require me to fill out certain parts that I had forgotten.

Also, anybody know of a really good tutorial on setting up HTML forms?

Thanks,

Well, I could write something in JavaScript for you that would validate forms, but I’m pretty sure somebody else has already done the work at one time or another. Try searching Google, but in the meantime, I’ll do my own search for you.

You would be best of using the cgi form as apposed to javascript to check for the required fields. This way people who have javascript disabled will still have there forms checked.

Yeah, I agree with iTec, because more & more hacks are using javascript these days, causing some informed people to disable javascript in their browsers.

I’m using the formmail script from http://nms-cgi.sourceforge.net/, you can see my actual configured script at: http://km.home.texas.net/cgi_project.html

How can I make this script validate my form fields, or at least validate the name & e-mail address fields… (without sacrificing security in any way)

thanks…

This is taken straight from the script that you posted:

<input type=“hidden” name=“required”
value=“name,comments”>

In other words, let’s say that you have something like this as your form:

<form name=“form1” method=“post” action=“formmail.pl”>
<p>
<input type=“text” name=“name”>
</p>
<p>
<input type=“text” name=“email”>
</p>
<input type=“submit” name=“Submit” value=“Submit”>
</form>

IF you want to make the name and email field REQUIRED you would change it to this:

<form name=“form1” method=“post” action=“formmail.pl”>
<p>
<input type=“text” name=“name”>
</p>
<p>
<input type=“text” name=“email”>
</p>
<p>
<input type=“submit” name=“Submit” value=“Submit”>
<input type=“hidden” name=“required” value=“name,email”>
</p>
</form>

HTH :slight_smile:

I’m sure what you told me was right, but it’s interferring with my script. Even when I put in the required info, the script shows an error message that says I have to put info in all fields.

Here’s a link to my configured perl script (on a webpage)…http://km.home.texas.net/cgi_project.html

No, wait. I didn’t set it up right. I’ll have to come back to this after I get back from traffic court!

I going on trial today, before a jury. I got a bunch of great info, including a list of questions to interogate the cop with on the stand, from http://www.CopRadar.com/

Jackie Chiles couldn’t do it no betta!

Thanks for your input…

OK. I’m now working on another form, and I can seem to get this “Required” stuff down.

I added what was suggested in this thread earlier, but to no avail.

Here’s the URL of my current test form…
http://www.austinsings.com/form_test.html

Also, how can I make it were the e-mail address box requires an actual email address, and not just text?

Thanks,
Rockrz

There’s 1 small problem with your form:


<input type="submit" value="Submit"><input type="reset" value="Clear Form"></form>
<input type="hidden" name="required" value="Name,Company Name,Street Address,City,State,Zip Code,Telephone,Email,Type of Business,Equipment Needs?,Check Acceptance Needs?"></form>

Notice that you have 2 closing form tags there. The hidden field is not getting passed on to formmail.pl because the hidden field “required” sits OUTSIDE of the FIRST CLOSING form tag.

change it to this:


<input type="submit" value="Submit"><input type="reset" value="Clear Form">

<input type="hidden" name="required" value="Name,Company Name,Street Address,City,State,Zip Code,Telephone,Email,Type of Business,Equipment Needs?,Check Acceptance Needs?">
</form>

You might also want to consider changing the Names of your form fields. Calling a form field “Check Acceptance Needs?” as you did here:

<SELECT NAME="Check Acceptance Needs?">

is not good practice. If you ever get into server side programming and databases, that type of form imput will bite you in the BEHIND :slight_smile:

As far as checking for a valid email address in the email field, the perl script that you are using doesn’t support it as is. You would have to add a bit of programming to it to check for an email address.
Your other option would be to use javascript to check for the field.

Try this:
http://javascript.internet.com/forms/email-validation---basic.html
but remember that javascript can be turned off.

HTH

I corrected where my closing tag was, but now when I recieve the message I no longer get the pre-determined message title in the subject line.

I’ll just go with the version where the fields aren’t verified. If one of their customers is serious about getting in contact, they’ll put in all the info. If they miss something, then they ought to pay closer attention.

Anyway, thanks very much for the tips…

I corrected where my closing tag was, but now when I recieve the message I no longer get the pre-determined message title in the subject line.

Try This:


 <input type="hidden" name="subject"
        value="From the feedback form" />

HTH

I went back to my original form that had that part working.

Thanx…