Form load based on condition

Reply

Join Date: Dec 2008
Posts: 11
Reputation: krm08 is an unknown quantity at this point 
Solved Threads: 0
krm08 krm08 is offline Offline
Newbie Poster

Form load based on condition

 
0
  #1
Jun 17th, 2009
Hi experts,
I'm extreme beginner in PHP.My problem is that,i've an html page and there's combobox on it,I want to load the form according to the selection of items.
The html page is
  1. <form action="search.php" method="post">
  2. <select name="option" size="1">
  3. <option value="1">value1</option>
  4. <option value="2">value2</option>
  5. <option value="3">value3</option>
  6. <option value="4">value4</option>
  7. </select>
  8. <input type="submit" />
  9. </form>

and the search.php:
  1. <?php
  2.  
  3. $v = $_POST['option'];
  4.  
  5. if($v==1)
  6. {
  7. ?>
  8. <form method="get" action="page1.php"></form>
  9.  
  10. <?php
  11. }
  12. if($v==2)
  13. {
  14. ?>
  15. <form method="get" action="page2.php"></form>
  16.  
  17. <?php
  18. }
  19. if($v==3)
  20. {
  21. ?>
  22. <form method="get" action="page3.php"></form>
  23.  
  24. <?php
  25. }
  26. if($v==4)
  27. {
  28. ?>
  29. <form method="get" action="page4.php"></form>
  30.  
  31. <?php
  32. }
  33. ?>
I want to navigate through the page according to the value in the variable v.
Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 68
Reputation: djjjozsi is an unknown quantity at this point 
Solved Threads: 10
djjjozsi djjjozsi is offline Offline
Junior Poster in Training

Re: Form load based on condition

 
0
  #2
Jun 17th, 2009
  1. <?php
  2. $forms=array(
  3. "1"=>"page1.php",
  4. "2"=>"page2.php",
  5. "3"=>"page3.php");
  6. ?>

build the form:
<form action="" method="post" name="Form">
...
select box <--
...</form>

On submit, check if the posted value is in the array:

  1. <?php
  2. if ( !empty( $_POST["option"] ) ) {
  3. $option = $_POST["option"];
  4. if ( !empty( $forms[$option] ) ) {
  5.  
  6. ?> <form method="get" action="<?php echo htmlspecialchars( $form[$option] );
  7. ?>"></form><?php
  8. } else {
  9. print "You have selected a non existing option...";
  10. }
  11. }
  12.  
  13. ?>
Last edited by djjjozsi; Jun 17th, 2009 at 3:17 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 11
Reputation: krm08 is an unknown quantity at this point 
Solved Threads: 0
krm08 krm08 is offline Offline
Newbie Poster

Re: Form load based on condition

 
0
  #3
Jun 17th, 2009
Thanks djjjozsi,
but my problem is not solved,
The form doesn't works
  1. <form method="get" action="<?php echo $forms[$option] ;
  2. ?>"></form><?php
but the arrays works.
It doesn't navigate to the page specified in the array
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 68
Reputation: djjjozsi is an unknown quantity at this point 
Solved Threads: 10
djjjozsi djjjozsi is offline Offline
Junior Poster in Training

Re: Form load based on condition

 
0
  #4
Jun 17th, 2009
if the user posted the form you want to redirect to the specified page?

header("Location: ". $forms[$option] );

notice that, you should not print or have outputted html codes to the display before this header location.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC