Monday, April 8, 2013

Submit html form using GET method and store form details in a text file

Create a html page as below...


<html>
<head>
<title>This is a Get Method HTML form</title>
</head>
<body>
<table border=1>

<form name="form1" method="get" action="getsubmit.php">
<tr><td>NAME:</td><td> <input type="text" name="name"></td></tr>
<tr><td>SEX:</td><td><input type=radio name="sex" value=Male>Male</td><td><input type=radio name="sex" value=Female>Female</td></tr>
<tr><td>EDUCATION LEVEL: </td><td> SSC<input type="checkbox" name="ssc" value="SSC"></td><td> HSC<input type="checkbox" name="hsc" value="HSC"></td><tr>
<tr><td>STATUS</td>
<td><select name="status">
<option selected value="">Select Your Status</option>
<option value="Married">Married
<option value="Unmarried">Unmarried
</option></select>
</td></tr>
<tr><td>COMMENT</td><td><textarea name="comment" cols="20" rows="8"></textarea></td></tr>
<tr><td><input type="submit" value=" SUBMIT " name="submit"></td><td></td></tr>
</form>

</table>
</body>

</html>
------------------------------------------------------------------------------------------------------
Now create the output or submitted page getsubmit.php

<html>
<head>
<title>This is a Get Method HTML form</title>
</head>
<body>
<?php
$name=$_GET['name'];
$sex=$_GET['sex'];
$ssc=$_GET['ssc'];
$hsc=$_GET['hsc'];
$status=$_GET['status'];
$comment=$_GET['comment'];

$posts = file_get_contents("posts.txt");
$posts = "$name - $sex - $ssc - $hsc - $status - $comment\n" . $posts;
file_put_contents("posts.txt", $posts);

print "Your Name Is:".$name;
?>
</body>
</html>

No comments:

Post a Comment