note 76795 deleted from tutorial.forms by philip
| From: | philip@php.net | Date: | Sat, 12 Apr 2008 04:19:47 +0000 |
| Subject: | note 76795 deleted from tutorial.forms by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-138204@lists.php.net to get a copy of this message | ||
Note Submitter: maheshs60 at gmail dot com
----
Here is a PHP script to add more form fields in a page by clicking on a button on the same page.You
can add unlimited number of fields dynamically(in run time) in a page by using this script.
(For the alligning of form fields,forms are given in layers)
<html>
<style type="text/css">
#Layer1 {
position:absolute;
left:413px;
top:123px;
width:203px;
height:35px;
z-index:1;
}
#Layer2 {
position:absolute;
left:21px;
top:122px;
width:389px;
height:50px;
z-index:2;
}
</style>
<body>
<?
$n=0;
$n1=$_POST['hf'];
if($n1>=$n){
$t=$n1;}
else{
$t=$n;}
/*For example this script allows user to add more and more file upload fields in a page by clicking
on a button*/
?>
<!--creating a form--><!--save this page as "upload.php" -->
<div id="Layer1">
<form name="form1" method="post" action="upload.php">
<!--creating a hidden field and sets it's value as $t-->
<input name="hf" type="hidden" id="hf" value="<? echo
++$t; ?>">
<!--creating a button.When we click this, a new field will be generated-->
<input type="submit" name="Submit" value="one more">
</form>
<!--another form to submit the uploaded file to be processed-->
<!--the upload script should be written in the file "uploader.php"-->
</div>
<div id="Layer2">
<form action="uploader.php" method="post"
enctype="multipart/form-data">
<p>
<?
$i=0;
while($i<$t){
echo "Filename:"
?>
<label for="file">
<input type="file" name="file" id="file" >
<input type="submit" name="submit" value="Submit" >
<?++$i;}?>
</form>
</div>
</body>
</html>
Like this, you can add any type of form field into the same page by the click of a button.