aznkidzx Posted January 27, 2009 Share Posted January 27, 2009 OK. I need a script that'll give an error like maybe a popup or message at top of form when a field is left out. Here's the code. <?php if ($_POST["email"]<>'') { $ToEmail = 'email@domain.com'; $EmailSubject = 'Contact '; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> Your message was successfully sent! <?php } else { ?> <form action="sendmail.php" method="post"> <table width="400" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="29%" class="bodytext"><strong>Name:</strong></td> <td width="71%"><input name="name" type="text" id="name" size="32"></td> </tr> <tr> <td class="bodytext"><strong>Email:</strong></td> <td><input name="email" type="text" id="email" size="32"></td> </tr> <tr> <td class="bodytext">Comment:</strong></td> <td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td> </tr> <tr> <td class="bodytext"> </td> <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php }; ?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted January 27, 2009 Share Posted January 27, 2009 Ok that's nice, try asking in the freelance section and i am sure someone will be happy to make you one at a small price. Quote Link to comment Share on other sites More sharing options...
bluesoul Posted January 27, 2009 Share Posted January 27, 2009 JavaScript is much more useful than PHP in this as you won't have to submit the page and then fool with variables and stuff. See this for form validation. Quote Link to comment Share on other sites More sharing options...
premiso Posted January 27, 2009 Share Posted January 27, 2009 JavaScript is much more useful than PHP in this as you won't have to submit the page and then fool with variables and stuff. See this for form validation. Although you may be right, if javascript is turned off, anyone can submit anything to that page without having it validated. Quote Link to comment Share on other sites More sharing options...
bluesoul Posted January 27, 2009 Share Posted January 27, 2009 JavaScript is much more useful than PHP in this as you won't have to submit the page and then fool with variables and stuff. See this for form validation. Although you may be right, if javascript is turned off, anyone can submit anything to that page without having it validated. More than likely, but I've had scant luck getting PHP to pop-up validation errors on-the-fly. Either way, the OP needs to at least take a stab at making it work. Quote Link to comment Share on other sites More sharing options...
kittrellbj Posted January 27, 2009 Share Posted January 27, 2009 Ok that's nice, try asking in the freelance section and i am sure someone will be happy to make you one at a small price. Blade is not being condescending or negative (at least I don't think he's trying to be), but form validation in PHP takes a toll on your sanity depending on how long the form gets. My site has a form with 15 fields to fill in, which is 77 lines of HTML/PHP, and a registration validator that is 157 lines, so about 200 lines of code for a 15 field registration page. Of course, mine sends emails on signup and puts an error message next to each field that is not filled out properly on submission, so that adds a good bit. But, it was no small task to make sure data was being validated and sanitized correctly, and that it was being inserted into the database just as I wanted it to. Since registration is one of the most vulnerable security areas, you have to adds lots of checking. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted January 27, 2009 Share Posted January 27, 2009 Blade is not being condescending or negative (at least I don't think he's trying to be), but form validation in PHP takes a toll on your sanity depending on how long the form gets. My site has a form with 15 fields to fill in, which is 77 lines of HTML/PHP, and a registration validator that is 157 lines, so about 200 lines of code for a 15 field registration page. That not why i said it, if i had loads of fields i would make a way to loop through them. We are giving up our free time to help people with php problems, we are not here just to write code for you. Laziness doesn't benefit you in learning a language. Quote Link to comment Share on other sites More sharing options...
kittrellbj Posted January 29, 2009 Share Posted January 29, 2009 Yes, I can definitely agree with you there. Quote Link to comment Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 More than likely, but I've had scant luck getting PHP to pop-up validation errors on-the-fly. Either way, the OP needs to at least take a stab at making it work. I am just saying, if you code validation in javascript you need to also code it in PHP. Anyone can easily create a form that posts to your form and in essence bypass the javascript check all together and now you get bad data. My approach is ajax and I use my PHP Validation function to check it, that way I only have to code validation once I am just saying, javascript is good to validate, but you need PHP to check due to people being able to easily get past the Javascript checks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.