Thread: required fields in a form
Results 1 to 15 of 18
Related
-
HTML Form with required fields Forum: HTML Forum
Replies: 10 -
Required Form Fields Forum: Javascript Forum
Replies: 1 -
required form fields in php page using redirect.php form Forum: PHP Forum
Replies: 1 -
How do I set up required fields in JMail form? Forum: ASP Forum
Replies: 3
-
03-22-2002, 06:41 PM #1
required fields in a form
Hello,
I'd like to know how to make certain text entry fields in a form mandatory. I can't seem to find the code anywhere.
Thanks alot.
San
-
03-23-2002, 02:27 AM #2
you could use this (if you have PHP enabled):
PHP Code:<?php
if ($form1 && $form2 && $form3) {
echo "Thank you for submitting your form";
} else {
echo "You have not filled out all the required fields. Place hit your back button and fill out all the required fields.";
}
?>
Code:<script language="javascript"> <!-- var form1 = formname.inputname.value if (form1==""&&Submit=1) { alert("You have not filled out all the required fields."); } var form2 = formname.inputname2.value if (form2==""&&Submit=1) { alert("You have not filled out all the required fields."); } var form3 = formname.inputname3.value if (form3==""&&Submit=1) { alert("You have not filled out all the required fields."); } --> </script>
-
03-23-2002, 02:45 AM #3
*fix*
Code:<script language="javascript"> <!-- var form1 = formname.inputname1.value var form2 = formname.inputname2.value var form3 = formname.inputname3.value if (form1==""&&Submit=1) { alert("You have not filled out all the required fields."); } if (form2==""&&Submit=1) { alert("You have not filled out all the required fields."); } if (form3==""&&Submit=1) { alert("You have not filled out all the required fields."); } else { location.href="blah.html"; } --> </script>
-
03-23-2002, 01:17 PM #4
-
03-23-2002, 01:58 PM #5
gee I love users who actually say thank you, a lot of them don't...
your welcome
-
03-24-2002, 01:59 PM #6
i use a simple code for that. it's let's the CGI script do all the work. here's the HTML:
<FORM METHOD=POST ACTION="cgi/bnbform.cgi">
<INPUT TYPE="HIDDEN" NAME="required" VALUE="name,email,message">
<INPUT TYPE="HIDDEN" NAME="data_order" VALUE="name,email,phone,subject,message">
<INPUT TYPE="HIDDEN" NAME="submit_to" VALUE="contact@whatever.com">
<INPUT TYPE="HIDDEN" NAME="form_id" VALUE="Contact from What Ever Dot Com">
<INPUT TYPE="HIDDEN" NAME="ok_url" VALUE="http://www.whatever.com/thanks.htm">
<INPUT TYPE="HIDDEN" NAME="not_ok_url" VALUE="http://www.whatever.com/oops.htm">
you can find this CGI script at http://www.bignosebird.com hope that helps.robert koons
-
03-25-2002, 02:26 PM #7
actually that javascript checker didn't even work I just tested it cause I was bored and came up with a working one:
Code:<html> <head> <script language="javascript"> <!-- function check() { if (document.daform.fname.value=="") { alert("You did not fill our your first name."); } if (document.daform.lname.value=="") { alert("You did not fill our your last name."); } if (document.daform.number.value=="") { alert("You did not fill our your number."); } else { location.href="blah2.html"; } } --> </script> </head> <body> <form name="daform"> First Name: <input type="text" size="15" name="fname"> <br> Last Name: <input type="text" size="15" name="lname"> <br> Number: <input type="text" size="15" name="number"> <br> <input type="Button" value="Submit" name="Submit" onclick="check()"> </form> </body> </html>
-
03-25-2002, 06:46 PM #8
what if you had an initial value set for the inputs. could you adjust the script to check for two options? like this maybe:
<script language="javascript">
<!--
function check() {
if (document.daform.fname.value=="enter your name here" "") {
alert("You did not fill our your first name.");
}
if (document.daform.lname.value=="") {
alert("You did not fill our your last name.");
}
if (document.daform.number.value=="") {
alert("You did not fill our your number.");
} else {
location.href="blah2.html";
}
}
-->
</script>
</head>
<body>
<form name="daform">
<input type="text" size="15" name="fname" value="enter your name here">
etc....robert koons
-
03-25-2002, 06:54 PM #9
you mean just adding this:
Code:<script language="javascript"> <!-- function check() { if (document.daform.fname.value=="Enter Your First Name") { alert("You did not fill our your first name."); } if (document.daform.lname.value=="Enter Your Last Name") { alert("You did not fill our your last name."); } if (document.daform.number.value=="Enter Your Number") { alert("You did not fill our your number."); } else { location.href="blah2.html"; } } --> </script>
-
03-25-2002, 07:02 PM #10
but will that still work if the field is empty?
robert koons
-
03-25-2002, 07:12 PM #11
No, you'd have to add this:
Code:<script language="javascript"> <!-- function check() { if (document.daform.fname.value=="Enter Your First Name") { alert("You did not fill our your first name."); } if (document.daform.fname.value=="") { alert("You did not fill our your first name."); } if (document.daform.lname.value=="Enter Your Last Name") { alert("You did not fill our your last name."); }if (document.daform.lname.value=="") { alert("You did not fill our your last name."); } if (document.daform.number.value=="Enter Your Number") { alert("You did not fill our your number."); } if (document.daform.number.value=="") { alert("You did not fill our your number."); } else { location.href="blah2.html"; } } --> </script>
-
03-25-2002, 07:13 PM #12
oh ya and be sure to make the form method=POST cause that fixes a little error that occurs if you play with the script you'd see it. Anyways later.
-
03-25-2002, 09:38 PM #13
lol sorry for dragging this on but there are little annoying (but can be costly) errors that I can't seam to fix so here's the code as it stands(if anybody cares):
Code:<html> <head> <script language="javascript"> <!-- function check() { if (document.daform.fname.value=="") { alert("You must fill out ALL fields."); } else if (document.daform.lname.value=="") { alert("You must fill out ALL fields."); } else if (document.daform.number.value=="") { alert("You must fill out ALL fields."); } else { location.href="blah2.html"; } } --> </script> </head> <body> <form name="daform"> First Name: <input type="text" size="15" name="fname"> <br> Last Name: <input type="text" size="15" name="lname"> <br> Number: <input type="text" size="15" name="number"> <br> <input type="Button" value="Submit" name="Submit" onclick="check()"> </form> </body> </html>
-
03-26-2002, 04:10 PM #14
When you say little errors, do you mean the fact that it doesn't actually submit any data?
Here revised code that actually submits -
Code:<html> <head> <script language="javascript"> <!-- function check() { if (document.daform.fname.value=="") { alert("You must fill out ALL fields."); return false; } else if (document.daform.lname.value=="") { alert("You must fill out ALL fields."); return false; } else if (document.daform.number.value=="") { alert("You must fill out ALL fields."); return false; } else { return true; } } --> </script> </head> <body> <form name="daform" onsubmit="return check()" action="blah2.php"> First Name: <input type="text" size="15" name="fname"> <br> Last Name: <input type="text" size="15" name="lname"> <br> Number: <input type="text" size="15" name="number"> <br> <input type="submit" value="Submit" name="Submit"> </form> </body> </html>
If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
03-26-2002, 04:37 PM #15
actually (I shoudl have thought of that one lol) but that wasn't the problem. In the old code, if you only filled out say the number, it would only say ou didnt' fill out the first name, when you hadn't filled out the last name either. Same when you typed in only the last name, etc. It's with the "else if"'s and stuff that I can't seam to fix to make it say all the fields you haven't filled out. And when I left just the plain if's it said all the ones you hadn't filled out, but if you filled out the number at all it would go to the destination even if you hadn't filled out the first to, so the else if's change that, but then give me the second problem. Well if you can solve it you deserve a cookie I spent like 20 mintes messing aroudn with it but coudln't get it to work.
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum