TheFilmGod Posted January 14, 2008 Share Posted January 14, 2008 What I am about to ask is a bit of html / a bit of php. I have: <ul> <li><a href="#">LINK HERE</a></li> </ul> I want to change the LINK HERE to a form. So I can use php to bring up the submitted info. The user has 5 options. I attached a picture. How can I do that? php part of the question --> How will I use php to grab the info? I want the form to be self-processing. Would I just do $_POST['submit'] or will it be different from the solution you gave me? Is this even possible? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/85987-ul-li-to-form-to-php/ Share on other sites More sharing options...
wildteen88 Posted January 14, 2008 Share Posted January 14, 2008 Why would you use a from to grab information based on the class the user clicked on? You'd be better of using a normal hyperlink and sending a query string instead. Eg: The link for Period 1 you'd do this <ul> <li><a href="class.php?period=1">Period 1</a></li> </ul> For the next period link you'll use the following: class.php?period=2 etc In class.php you'd use the following code for returning specific information based on the period number sent in the link <?php // Get the period id number from the query string if(isset($_GET['period']) && is_numeric($_GET['period'])) { $requested_period = $_GET['period']; } // period id number is not present or is invalid, we'll set the requested_period variable to the string "invalid". // This will be used later on. else { $requested_period = 'invalid'; } // Now that we have the period id we can return the data based on that id switch($requested_period) { case '1': // show information for period1 break; case '2': // show information for period2 break; case '3': // show information for period3 break; case '4': // show information for period4 break; case '5': // show information for period5 break; case 'invalid': default: // show error message, as the provided id number does not exists or is not present break; } Quote Link to comment https://forums.phpfreaks.com/topic/85987-ul-li-to-form-to-php/#findComment-439162 Share on other sites More sharing options...
redarrow Posted January 14, 2008 Share Posted January 14, 2008 done this for fun trie it <?php echo" <a href='".$_SERVER['PHP_SELF']."?form=form1'>WHAT YOUR FAV COLOR</a><br> <a href='".$_SERVER['PHP_SELF']."?form=form2'>WHAT YOUR FAV PET</a><br> <a href='".$_SERVER['PHP_SELF']."?form=form3'>WHAT YOUR FAV NAME</a><br> <a href='".$_SERVER['PHP_SELF']."?form=form4'>WHAT YOUR FAV PARK</a><br> <a href='".$_SERVER['PHP_SELF']."?form=form5'>WHAT YOUR FAV PLACE</a><br>"; if($_GET['form']=="form1"){ echo "<br><br> <form method='POST' action=".$_SERVER['PHP_SELF']."?form=1> <br> What your fav color <br> <input type='text' name='color'> <input type='submit' name='submit' value='SEND'></form>"; } if($_GET['form']=="form2"){ echo "<br><br> <form method='POST' action=".$_SERVER['PHP_SELF']."?form=2> <br> What your fav pet <br> <input type='text' name='pet'> <input type='submit' name='submit' value='SEND'></form>"; } if($_GET['form']=="form3"){ echo "<br><br> <form method='POST' action=".$_SERVER['PHP_SELF']."?form=3> <br> What your fav name <br> <input type='text' name='name'> <input type='submit' name='submit' value='SEND'></form>"; } if($_GET['form']=="form4"){ echo "<br><br> <form method='POST' action=".$_SERVER['PHP_SELF']."?form=4> <br> What your fav park <br> <input type='text' name='park'> <input type='submit' name='submit' value='SEND'></form>"; } if($_GET['form']=="form5"){ echo "<br><br> <form method='POST' action=".$_SERVER['PHP_SELF']."?form=5> <br> What your fav place <br> <input type='text' name='place'> <input type='submit' name='submit' value='SEND'></form> "; } if( ($_GET['form']==1) || ($_GET['form']==2) || ($_GET['form']==3) || ($_GET['form']==4) || ($_GET['form']==5) ){ $color=$_POST['color']; $pet=$_POST['pet']; $name=$_POST['name']; $park=$_POST['park']; $place=$_POST['place']; echo "$color <br> $pet <br> $name <br> $park <br> $place"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85987-ul-li-to-form-to-php/#findComment-439201 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.