HomeMonday, August 29, 2016, 08:49:05
1

PHP Form Validation

Tuesday, February 10, 15, 13:18:12, 2 Yaers Ago Via wain, Hits: 780
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

Web Hosting
First Month Free with Coupon Code phpmonth
Unlimited Domains - Unlimited Storage
Unlimited Transfer - Unlimited Email
Related

Timed Redirect JavaScript

Timed redirect javaScript/PHP example

PHP Forms

FREE PHP forms

Creating a CAPTCHA with PHP :: PHP Tutorial

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

PHP $_POST Function

Collect values from a form sent with method post

Smarty Paginate Example - Smarty Pagination with PHP

Smarty Paginate Example, Smarty Pagination with PHP. SmartyPaginate: a class/plugin for data set pagination within the Smarty template environment

PHP Jquery Form

PHP Jquery Form allow your visitors to contact you directly from your website.

Upload Image with PHP [Example2]

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

MySQL – Select from two tables

Select data from two tables, PHP MySQL

PHP Links Script 1.1.

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. The script is easy to customize to suit your needs.

FeedBack Form with Captcha

It allows your visitors to send you an email directly from your website.
About Author

wain

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