One Form Multiple Processing in PHP

Introduction

In this article I will explain one form multiple processing in PHP. In one form you can do multiple things such as adding a record and searching for a record. For this explanation I am using simple  HTML and a PHP script. This article uses one simple form to show how to work with multiple processes.   

image1.jpg

This is a simple HTML form for doing the form design. Save this form with a name such as "form.php".

<html>

<head>

<title>Add/search/Entry</title>

</head>

<body bgcolor="#EAE6FF">

<form action="process.php"method="post">

<table>

<tr>

<td>Name</td>

<td><input type="name" name="name"></td>

</tr><tr>

<td>movie type</td>

<td>

<select name="name_type">

<option value="">select a movie type</option>

<option value="teacher">teacher</option>

<option value="student">student</option>

<option value="employee">employee</option>

</select>

</td>

</tr><tr>

<td>Item Type</td>

<td>

<input type="radio" name="type" value="teacher" checked="checked">teacher<br>

<input type="radio" name="type" value="student">student<br>

<input type="radio" name="type" value="employee">employee<br>

</td>

</tr><tr>

<td> </td>

<td><input type="checkbox" name="debug" checked="checked">

Display Debug Information</td>

</tr><tr>

<td colspan="2" style="text-align:center">

<input type="submit" name="submit" value="search">

<input type="submit" name="submit" value="Add">

</td>

</tr>

</table>

</form>

</body>

</html>

 

This is a PHP script that saves this file as "process.php":

<?php

if($_POST['type']== 'teacher' && $_POST['name_type']=='')

{

Header('location:form.php');

}

?>

<html>

<head><title><?php echo $_POST['submit'] . '' . $_POST['type'] . ': ' . $_POST['name'];?></title>

</head>

<body>

<?php

if(isset($_POST['debug']))

{

echo '<pre>';

print_r($_POST);

echo '<pre>';

}

 

$name= ucfirst($_POST['name']);

if($_POST['type']=='teacher')

{

 $foo=$_POST['name_type'] . '' . $_POST['type'];

 

}

else

{

$foo=$_POST['type'];

}

echo '<p> You are' . $_POST['submit'] .'ing ';

echo ($_POST['submit']=='search') ? 'for ' : '';

 

?>

</body>

</html>

First of all enter a name for the search, select a movie type and choose an item type. Then click on the "Search" button.

searching for.jpg

Output

Searching output.jpg

First of all enter a name to be added, select a movie type and choose the item type. Then click on the "Add" button.

Adding for.jpg

Output 

Adding output.jpg