Results 1 to 4 of 4
Thread: Form warning?
-
10-23-2003, 01:37 PM #1Junior Guru
- Join Date
- Jun 2003
- Location
- New York
- Posts
- 189
Form warning?
I have a script i've written, it's a simple contact form that sends email to me from users input. I have some if() statements in there that make sure the user fills in all the fields. I'm using the POST method so when the user hits submit the script checks to make sure all fields are filled in, if one is empty it displays a message on the page asking to go back and fill it in.
Example:
PHP Code:if (!strlen($_POST['name'])){
print '<br><br><br>
<table border="1" bordercolor="black" width="300">
<tr>
<td bgcolor=silver><div align=center>Please enter your name.<br>
<A HREF="javascript:history.go(-1);">Back to the previous page.</A></div>
</td>
</tr>
</table>';
exit;
}
John DeLutri
President - Lightning Technologies, Inc.
Web hosting is simple math: Fast+Reliable+Service=Happy Customer
-
10-23-2003, 03:17 PM #2Web Hosting Master
- Join Date
- Sep 2002
- Location
- Illinois
- Posts
- 2,307
You have two choises here
1) JavaScript method
2) PHP method
1) This method will check if fields are enter before form is submitted
Here is an example
http://www.w3schools.com/js/tryit.as...s_formvalidate
2) You will need to use a script that checks the form values after submit. If error occurs script should return user back to the form and fill the form with the values that user already entered.
Hope this helps
nullHow's my programming? Call 1-800-DEV-NULL
-
10-23-2003, 07:25 PM #3Junior Guru
- Join Date
- Jun 2003
- Location
- New York
- Posts
- 189
Thanks, I'll look into that.
John DeLutri
President - Lightning Technologies, Inc.
Web hosting is simple math: Fast+Reliable+Service=Happy Customer
-
10-23-2003, 09:04 PM #4Web Hosting Master
- Join Date
- Mar 2003
- Location
- MD
- Posts
- 640
If I am reading this right, you are wanting to do something like this in regards to PHP.
PHP Code:<?php
if (!submit) {
if (!strlen($_POST['field1']) || !strlen($_POST['field2'])) {
//error line goes here
} else {
//mail function goes here
}
}
?>