Form validation problem

 
Post new topic   Reply to topic    Aprelium Forum Index -> Web Design
View previous topic :: View next topic  
Author Message
almadera
-


Joined: 17 Mar 2008
Posts: 2

PostPosted: Mon Mar 17, 2008 12:43 pm    Post subject: Form validation problem Reply with quote

I'm using Godaddy's gdform.php form mailer for my forms. The forms work perfectly except the validation. I need the visitors to fill in the fields and then submit the information to my email, but the problem is that everyone can submitt even if he doesn't fill in the form. I want all of the fileds to be required. Is there something wrong with the code ? Here it is :




<form action="/gdform.php" method="post">
<table align="center">
<input type="hidden" name="subject" value="Form Submission">
<input type="hidden" name="redirect" value="/Add/thankmes.html">
<input type="hidden" name="required" value="YourName, Email, description">
<tr>
<td><p><font color=WHITE font size=4>Your Name:</p> </font></td> <td align=center height=50><p><input type="text" name="YourName" size="52"/></p></td>
</tr>
<tr>
<td><p><font color=WHITE font size=4>Your E-mail:</p> </font></td> <td height=50><p><input type="text" name="Email" size="52"/></p></td>
</tr>

<tr>
<td><p><font color=WHITE font size=4>Your Message:</p> </font></td> <td><br><p><textarea name="description" cols="40" rows="5">
</textarea></p></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Send"/></td>
</tr>
</table>
</form>
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 882
Location: Michigan, USA

PostPosted: Mon Mar 17, 2008 9:34 pm    Post subject: Reply with quote

Two ways to do it:
1. Javascript - does the validation right then and there - no pages needed to load
2. PHP - more validation control - requires form to be submitted to itself and checked, giving any errors

I'd say Javascript is probably easier, if you're inclined to use it.

Google is probably your best friend --> javascript form validation
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3719
Location: USA, GA

PostPosted: Mon Mar 17, 2008 10:12 pm    Post subject: Reply with quote

It's good practice to validate a form from the client and server side. If the client has JavaScript disabled, you must have a server side way of checking for errors too; especially if that data goes to a database!
_________________
Computer Programmer & Networking Specialist

Back to top View user's profile Send private message Visit poster's website MSN Messenger
almadera
-


Joined: 17 Mar 2008
Posts: 2

PostPosted: Tue Mar 18, 2008 12:44 pm    Post subject: Reply with quote

I'm using Godaddy's gdform.php form mailer for my forms. The forms work perfectly except the validation. I need the visitors to fill in the fields and then submit the information to my email, but the problem is that everyone can submit even if he doesn't fill in the form. I want all of the fields to be required.

Here is my form script :


<form action="/gdform.php" method="post">
<table align="center">

<input type="hidden" name="subject" value="Form Submission">
<input type="hidden" name="redirect" value="/Add/thankmes.html">
<input type="hidden" name="required" value="YourName, Email, description">

<tr>
<td><p><font color=WHITE font size=4>Your Name:</p> </font></td> <td align=center height=50><p><input type="text" name="YourName" size="52"/></p></td>
</tr>

<tr>
<td><p><font color=WHITE font size=4>Your E-mail:</p> </font></td> <td height=50><p><input type="text" name="Email" size="52"/></p></td>
</tr>

<tr>
<td><p><font color=WHITE font size=4>Your Message:</p> </font></td> <td><br><p><textarea name="description" cols="40" rows="5">
</textarea></p></td>
</tr>

<tr>
<td><input type="submit" name="submit" value="Send"/></td>
</tr>

</table>
</form>


And here is the gdform.php script :

<?php
$request_method = $_SERVER["REQUEST_METHOD"] ;
if($request_method == "GET"){
$query_vars = $_GET;
} elseif ($request_method == "POST"){
$query_vars = $_POST;
}
reset($query_vars);
$t = date("U");

$file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
$fp = fopen($file,"w");
while (list ($key, $val) = each ($query_vars)) {
fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\n");
fputs($fp,"$val\n");
fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\n");
if ($key == "redirect") { $landing_page = $val;}
}
fclose($fp);
if ($landing_page != ""){
header("Location: http://".$_SERVER["HTTP_HOST"] ."/$landing_page");
} else {
header("Location: http://".$_SERVER["HTTP_HOST"] ."/");
}


?>


The user can fill in any, all, or none of the fields and submit. Does anyone know how to edit the gdform.php code so it doesn't pass empty fields ?


almadera
View Public Profile
Send a private message to almadera
Find all posts by almadera
Back to top View user's profile Send private message
rrinc
-


Joined: 24 Feb 2006
Posts: 725
Location: Arkansas, USA

PostPosted: Wed Mar 19, 2008 1:13 am    Post subject: Reply with quote

almadera wrote:
Does anyone know how to edit the gdform.php code so it doesn't pass empty fields ?
I would do some checking on all the variables such as:
Code:
if (empty($variable))
{
     // Don't use the var or whatever
}
else
{
     // The var has contents so proceed
}
You could use a loop to get everything checked with less code.
_________________
-Blake | New Server :D
SaveTheInternet
Soy hispanohablante. Puedes contactarme por mensajes privados.
Back to top View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
shovon
-


Joined: 30 Jul 2009
Posts: 2

PostPosted: Thu Jul 30, 2009 2:42 pm    Post subject: Reply with quote

Hi People,

I have a huge dilemma and I was hoping that somebody better versed could help. I volunteer for a IT comapny and one of the employees asked me to create a website. Needing the experience I did so. But I asked thge tech guys to help set up an email form - which they then did.

Using some php and javascript they set up a mail program which validates and takes input and structures into a html email which is then sent to the client email.

However the "client" (no pay (-_-)-sux!!) then said she wanted one of the form field values to change so that it would accept something like: 09/15/1989 - 12/01/2009 as a value. Currently the date value only accepts one date value ie. 03/01/1999 and anything else doesn\t validate. I have fond the javascript file for the validation, but the tech team are too busy too help and my knowledge of javascript isnt advanced enough yet.

Could someone point out the values that I may need to change - I cant differeniatiate between the strings in the file.

the form code is:

Quote:
<form method="post" name="booking_field_form" action="mailform.php">
<table border="0" summary="This form will enable you to book viewings or property rentals">
<tr>
<td width="91">Name:</td>
<td width="159"><input name="Name" type="text" value=""/></td>
</tr>
<tr>
<td>Dates Interested In (mm/dd/yyyy):</td>
<td><input name="date1" type="text" value=""/></td>
</tr>
<tr>
<td width="91">Email Address:</td>
<td width="159"><input name="email_address" type="text" value=""/></td>
</tr>
</table>
<table border="0" cellpadding="3">
<tr>
<td><input type="submit" name="button" id="lightbox1" value="Submit"/> </td>
<td><input type="reset" name="Reset" id="button2" value="Reset" /></td>
</tr>
</table>
</form>
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Web Design All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group