Ad block is installed and active. Please support us by disabling it.
HomeSunday, December 17, 2017, 04:12:29
3

PHP Form Validation

Tuesday, February 10, 15, 13:18:12, 3 Yaers Ago Via wain, Hits: 3237
PHP form validation :: PHP tutorial, requirement(s): PHP Server
Download source code:
http://phpform.net/download.php?f=validation.zip

Code:
<?php
if(isset($_POST['submit']))
{
$mail = $_POST['mail'];
$subject = $_POST['subject'];
$msg = $_POST['msg'];
$headers = 'From: System <noreply@example.com>';
$name=array($mail,$subject,$msg);
foreach ($name as $name)
{
if (ereg("^\<",$name)) {
echo "<center>Invalid Characters:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
if (ereg("^\[",$name)) {
echo "<center>Invalid Characters:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
if (ereg("^\$",$name)) {
echo "<center>Invalid Characters:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
if (strlen($name) < 3) {
echo "<center>Field must be at least 3 characters long:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
if (strlen($name) > 120) {
echo "<center>Max Characters in Field: 120
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
}
mail($mail, $subject, $msg,$headers);
echo "O.K.";
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function validationEmail(maForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(maForm.mail.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}
</script>
</head>
<form name="maForm" action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="POST" onSubmit="return validationEmail(this)">
<input type=text name="mail" value="e-Mail"><br>
<input type=text name="subject" value="e-Mail subject"><br>
<input type=text name="msg" value="e-Mail message"><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
}
?>

Sign In

Sponsor

Related

Email Link

HTML email link example

Link Base Pro :: Free Link Index Script

This script allows you to manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links.

Syntax highlighting in Smarty

Syntax highlighting for Smarty - Google Code Prettify

Creating a Math CAPTCHA with PHP - PHP Tutorial

This tutorial will show you how to create a form with Math Captcha.

Email to Friend - PHP Script

This form allows your visitors to suggest your site to a friend. It features an HTML email format and an admin notification email.

MySQL Basic Functions

MySQL Basic Functions - select, delete, update..

PHP Cookies - setcookie

Defines a cookie to be sent along with the rest of the HTTP headers.

Upload Image with PHP [Example2]

[Example2] Tutorial - How to upload and resize image with PHP

View content in a zip file with PHP

List all files in a zip archive with PHP

PHP Cookies and Sessions Tutorial

PHP Cookies and Sessions Tutorials
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Thu, Jun 15, 17
So far has created 115 entries.
wain
This author has not yet filled in any details.