开发者

to call same form many times depending upon a value enterd by a user

I am now developing a travel agency website, in this site when the user reserves a trip he/she have to enter trip related details. This information is collected in a forma. The user also enters the number of people who are travelling.

My question is, how do I gather the same information for everyone who is travelling? Basically I need the form to be generated many times depending upon the number of people of same family ,, so I can capture all their data. How do I do this?

well there are my Code;plllz help me am so confused and tried lots of things to solve it; thanks in advance

<form action = "insertpassenger.php" method = "POST">
  <center>Enter all the information below</center>
  <?php for 开发者_如何学Python($i=0;$i<$pplno;$i++) : ?> 
     people<?php echo $i+1 ; ?> 
     <input type="text" name="cpr" size="9" value="<?php echo $cpr;?>" maxlength="9">CPR 
     <input type="text" name="pplno" size="30" maxlength="25">Number Of People 
     <input type="text" name="gcpr" size="9" maxlength="9">dad CPR 
     <input type="reset" value="clear" name="clear"> 
     <input type="submit" value="join" name="join"> 
  <?php endfor; ?> 
</form>


Your code jumps in and out PHP rather a lot.

Just declare the item names as array entries, either with implicit or explicit numbering:

for ($i=0;$i<$pplno;$i++) : ?>  
 <input type="text" name="cpr[]" size="9" value="<?php echo $cpr[$i];?>" maxlength="9">CPR 
 <input type="text" name="pplno[]" size="30" maxlength="25">Number Of People 
 <input type="text" name="gcpr[]" size="9" maxlength="9">dad CPR 
 <input type="reset" value="clear[]" name="clear"> 
 <input type="submit" value="join[]" name="join"> 
<?php endfor; 

or...

for ($i=0;$i<$pplno;$i++) {  
 print "<input type=\"text\" name=\"cpr[$i]\" size=\"9\" value=\"$cpr[$i]\" maxlength="9">CPR";
 ....
}


I would personally use a session variable and count down how many times the form needs to be completed. Unfortunately that would cause to page to reload after each form entry, but this allows you to have as many amount of forms as your user requests, without a screen scrolling down a few pages to create all the forms on one page.

At the start of your code before you displaying anything to the browser :

<?php 
session_start ();
?>

And where you receive your count for looping:

<?php 
if (!isset($_SESSION['yourAppName'])) 
}
    $_SESSION['yourAppName'] = $pplno;
} else {
    $_SESSION['yourAppName']--;
}
if ($_SESSION['yourAppName'] > 0) { 
    ?>
<form action=''>
    <input type="text" name="cpr" size="9" value="<?php echo $cpr;?>" maxlength="9">CPR 
    <input type="text" name="pplno" size="30" maxlength="25">Number Of People 
    <input type="text" name="gcpr" size="9" maxlength="9">dad CPR 
    <input type="reset" value="clear" name="clear"> 
    <input type="submit" value="join" name="join"> 
    <input type="submit" value="Proceed">
</form>
<?php 
} else {
    // code when all forms are filled in
}
?>

remember to have your form return to the same page. This code is only to guide you, don't expect it to work without some editing. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜