Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Form validation problem
Old 03-17-2008, 04:37 AM Form validation problem
Novice Talker

Posts: 9
Trades: 0
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>

Last edited by Almadera; 03-17-2008 at 05:03 AM..
Almadera is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-17-2008, 05:09 AM Re: Form validation problem
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Your validation doesn't really have anything to do with the html code you just posted. It'll actually be taking place through (I assume) the gdform.php file.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-17-2008, 06:10 AM Re: Form validation problem
Novice Talker

Posts: 9
Trades: 0
Quote:
Originally Posted by VirtuosiMedia View Post
Your validation doesn't really have anything to do with the html code you just posted. It'll actually be taking place through (I assume) the gdform.php file.
Unfortunately this isn't happening, and I don't know why. Is there a problem with the gdform.php file ?
Almadera is offline
Reply With Quote
View Public Profile
 
Old 03-17-2008, 07:08 AM Re: Form validation problem
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
He means you'll need to post the code from the php file, if there is anything wrong with it then it will be in there.
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 03-17-2008, 08:22 AM Re: Form validation problem
Novice Talker

Posts: 9
Trades: 0
Here is the gdform.php code :


<?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 is offline
Reply With Quote
View Public Profile
 
Old 03-17-2008, 08:51 AM Re: Form validation problem
Novice Talker

Posts: 5
Trades: 0
best way to do it would be to add some javascript
<script>
function IsEmpty(aTextField) {
if ((aTextField.value.length==0) ||
(aTextField.value==null)) {
return true;
}
else { return false; }
}
</script>
Add the above javascript into the html

and change ur form tag to this , make sure u use the correct form name
<form name=form1 action=/gdform.php method=post onsubmit="javascript:return IsEmpty
(this)">

That should be all.
mail8769 is offline
Reply With Quote
View Public Profile
 
Old 03-17-2008, 09:12 AM Re: Form validation problem
Novice Talker

Posts: 9
Trades: 0
Where exactly should I add this javascript ? You mean, I have to rewrite the forms entirely ?
Almadera is offline
Reply With Quote
View Public Profile
 
Old 03-17-2008, 02:14 PM Re: Form validation problem
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
JavaScript can be turned off, so you don't want to rely on it for form validation. It's nice because it can inform the user before they submit the form that it needs correcting, but you will also need to validate the form using PHP.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-17-2008, 05:10 PM Re: Form validation problem
Novice Talker

Posts: 9
Trades: 0
Quote:
Originally Posted by VirtuosiMedia View Post
but you will also need to validate the form using PHP.
This is the problem : I don't know how !
Almadera is offline
Reply With Quote
View Public Profile
 
Old 03-17-2008, 05:49 PM Re: Form validation problem
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Try this:
http://www.php-mysql-tutorial.com/fo...n-with-php.php
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Reply     « Reply to Form validation problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32521 seconds with 12 queries