on air

Create & Process Web Form Using PHP.

back home » Scripting Tutorials » PHP » Create & Process Web Form Using PHP.

Files Needed.

This Tutorial Requires The Basic Knowledge Of HTML And CSS.

Creating The Required Web Form.

In the first place, you'll create an HTML document, copy the Web Form Script below, paste it into the <body> tag of your HTML document, edit it as required, and save it as [userdata.php].

Web Form Script. [userdata.php]

<form name="userdata" method="post" action="verify.php" 
onsubmit="return checkfields()">  
<table align="center">  
<td colspan="2">
<p><strong>Contact Form:</strong></p>
<p>Select Title:</p>
<select name="Title">
<input type="hidden" value="youremail@yoursite.com" name="sendto">
<td><p><span style="color:#F00">*</span> Full Name:</p></td> 
<td><input size=35 name="Name"></td> 
<td><p><span style="color:#F00">*</span> Email Address:</p></td> 
<td><input size=35 name="Email"></td> 
<td><p>Send Me News:</p></td> 
<td><p><input type="radio" name="list" value="Mothly">  
Monthly.<br><input type="radio" name="list" value="Weekly" checked />  
<td colspan="2" align="center">
<input type="reset" value="Reset" />
<input onclick="validate();" type="button" value="Submit" /> 
<td colspan="2" align="center">
<p style="font-size:10px">
<span style="color:#F00">*</span> indicates field is required.

Note The Following, Inside The Script Above Carefully.

  • <form name="userdata">
    • You should give your Web Form a unique name you can later refer to from a script like JavaScript. See Script Below.
  • <form method="post">
    • Your Web Form should use the attribute method= "post" because in this case, it's the user posting information.
  • <form action="verify.php">
    • The attribute action should contain a value "verify.php", which is the Web Form Processor file you'll create. And this must also reside inside the same folder containing the rest of your file.

Creating The Required Web Form Processor. [PHP]

This Tutorial Requires The Basic Knowledge Of PHP And HTML.

Now, you'll create another file. Copy the Web Form Processor Script below into it, edit it appropriately and save it as verify.php.


The <form> element above, contains an "action" attribute with a value "verify.php".

This tells you that, user data when submitted, will be sent to a destination file named "verify.php", which is the Web Form Processor file you are about to, or may have just created.

Web Form Processor.[verify.php]

//Add your reCAPTCHA Private Key script here.  
$to = $_POST['sendto'] ; 
$Title = $_POST['Title']; 
$from = $_POST['Email'] ;  
$name = $_POST['Name'] ;  
$headers = "From: $from";  
$subject = "User Subscribtion Data";
$fields = array();  
$fields{"Name"} = "Name";    
$fields{"Email"} = "Email";    
$fields{"list"} = "Mailing List";
$body = "I have received the following information:\n\n";
foreach($fields as $a => $b){ 
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
$headers2 = "From: noreply@yoursite.com";
$subject2 = "Thankx for your mail";  
$autoreply = "Thankx for your mail. I'll get back to you very soon.";
$send = mail($to, $subject, $body, $headers);  
$send2 = mail($from, $subject2, $autoreply, $headers2);  
{header( "Location: https://www.yoursite.com/contact/thankyou.html" );}
{print "Error occured sending your mail, notify info@yoursite.com"; }

You'll Need To Edit The Following Lines In The Above Script.

  • Adding reCAPTCHA is optional. However, attaching it to your Web Form extends its security.
    • Using reCAPTCHA you'll also be helping in digitizing old books written before the existence of Computer.
  • You may edit the information on the line that reads; $subject = "My Site1 User Data"
    • This is the title notifying you from where the data is coming.
  • You must edit the line that reads: https://www. yoursite.com/contact/thankyou.html
    • This is the file that will load after a successful data sending by a user. It must be placed inside the same folder your Web Form and Processing files are residing.
  • And the line that says; "Error occurred sending your mail, notify info@yoursite.com" must also be edited appropriately.

FastLaneTip #1.

Please note that your files must be uploaded onto a web server before they'll work.

Validate Form Behavior | JavaScript.

This Tutorial Requires The Basic Knowledge Of Javascript And HTML.

Javascript Function.

Copy and paste the javascript below into the <head> section of the HTML document holding your Web Form. This will take care that users enter data into the required fields. However, script must be edited according to your form scripting data.

Add the following attribute and value into the <body> tag like this; <body onload="reset()">

Below Is The Required Javascript.

<script language="javascript">
function reset() {
function validate() {
if (document.userdata.Name.value.length==0) {
  alert("Please Enter Your Full Name ");
  return false;
if (document.userdata.Email.value.length==0) {
  alert("Please Enter Your Email Address");
  return false;
  return true;

Extend The Security For Your Web Form.

After creating your Web Form, securing the required fields, and processing it using the provided scripts.

The next important thing you'll want to add into the extension of securing your Web Form is, attaching it with a CAPTCHA. Now learn how to implement this from the adding CAPTCHA to PHP tutorial.

How To Create And Process Web Form.

Hope you're able to add it, if not try again. Good Luck.


Man will give you worldly powers, and make you feel on top of all, note this is temporally and could be redrawn at anytime sending you back to the ground floor of life. However, the Lord Almighty, the one and the only rightful ruler of the Universe, blesses everlastingly.


Knowledge is Power, but Power is not Knowledge. Wisdom is the truthful Power that identifies the Knowledge within the man. And only, I repeat 3x. Only the almighty God has the power to bless the man with his Wisdom forever.

To achieve the Lord's blessings, cease not praying daily, asking for his Wisdom, and you'll be blessed abundantly...

Advertise your business here

Advertising your business means a lot to us. For less than 20€, you can place your business ad here and start receiving traffic.

Place your ad here


Spyera Phone

Spyera Phone version is software that you install on a smart phone to monitor everything happening on the phone. After installation, SPYERA secretly records events (sms, call history, phone book, location, emails, What's App messages, IM, Facebook Chat, Skype, See photos taken and many more...) that happen on the phone and delivers these information to a web account, where you can view these reports 24/7 from any Internet enabled computer or mobile phone. SPYERA also allows you to listen to the surroundings of the target mobile , listen to the phone conversation and to know the location of the device.


Please, Kindly Donate What You Can, Enabling Us Pay Hosting And Domain Costing, And Do More.

Please Donate