MartinTheNob MartinTheNob - 3 months ago 9
HTML Question

Extract html input with php

I am new to php and want to make a dropdown menu where you can select a site that you want, then when you click a button you will be redirected to that site. The button will take you to for example "google.com" if that is what you select, if you select "stackoverflow.com" the same button will take you there. I currently have no working php code as I am not sure where to start. I will include the html code below.

<form method="post" action="testttt.php">
<select id="mySelect" onchange="myFunction()">
<option value="SelectSite"> Select Site Please
<option value="Itslearning"> Itslearning
<option value="NDLA"> NDLA
</select>

<input type="submit" value="GO"/>


The form ends a bit further down, so please don't complain about there being no :P ANY HELP IS APPRECIATED :)

Answer

Try the below code , i have done the example which you want and its work perfectly . You can do it this in single file as i have done .

<?php
if(isset($_POST['btnsubmit']))
{

    $options = $_POST["testing"];
    header('Location: '.$options.'');
    echo "Your option value".$options;
}

?>
<form method="post" action="#">
<select id="mySelect" name="testing" onchange="myFunction()">  
    <option value="SelectSite"> Select Site Please
    <option value="http://www.google.com"> Itslearning
    <option value="http://www.stackoverflow.com"> NDLA
</select>

    <input type="submit" name="btnsubmit" value="GO"/>
</form>