0

Hello guys,

I'm writing a code that will display another form when the submit button on the first form is clicked (isset). However on the second form, there is nothing happen after i clicked the second submit button line 62. The javascript alert seems to be not executed. Any idea why?

Any help would be appreciated

<?php
if(!isset($_POST['submitButton']))
{
    echo "<div id=\"first\">";
    echo "<h4>Would like us to recommend a class for you ?<br><br> </h4>";
    echo "<form name=\"searchMethod\" id=\"searchMethod\" method=\"post\" action=\"class_booking.php\">";

    echo "<input type=\"radio\" name=\"recommend\" value=\"1\"> Yes<br><br>";
    echo "<input type=\"radio\" name=\"recommend\" value=\"2\"> No, I would like to search manually<br><br>";


    echo "<input type=\"submit\" name=\"submitButton\" value=\"Submit\">";
    echo "</form>";
    echo "</div>";

}
?>
<?php    
if(isset($_POST['submitButton']))
{
    $answer = $_POST['recommend'];

    if($answer == 1)
    {
        echo "<h4>Please select the options you prefer<br><br></h4>";
        echo "<div id=\"regtable\">";
        echo "<form name=\"submitRecommend\" id=\"submitRecommend\" method=\"post\" action=\"class_booking.php\">";  
        echo "<fieldset><legend><b>Date and Time</b></legend>";
        echo "<input type=\"text\" size=\"12\" name=\"attdate\" id=\"inputField\" title=\"Date -Click Here\"  /></br></br>";
        echo "<select name=\"searchTime\">";
        echo "<option value=\"\">Time</option>";
        echo "<option value=\"1\">Morning (8am - 12pm) </option>";
        echo "<option value=\"2\">Afternoon (12pm = 6pm)</option>";
        echo "<option value=\"3\">Evening (6pm - 8pm)</option>";
        echo "</select><br><br>";                                                                                                  
        echo "</fieldset>";


        echo "<fieldset><legend><b>Floor</b></legend>";
        echo "<select name=\"searchFloor\">";
        echo "<option value=\"\">Floor</option>";
        echo "<option value=\"1\">1</option>";
        echo "<option value=\"2\">2</option>";
        echo "<option value=\"3\">3</option>";
        echo "<option value=\"4\">4</option>";
        echo "<option value=\"5\">5</option>";
        echo "</select><br><br>";
        echo "</fieldset>";


        echo "<fieldset><legend><b>Pax</b></legend>";
        echo "<select name=\"searchPax\">";
        echo "<option value=\"\">Pax</option>";
        echo "<option value=\"1\">1 - 5</option>";
        echo "<option value=\"2\">5 - 20</option>";
        echo "<option value=\"3\">20 - 40</option>";
        echo "<option value=\"4\">40 - 100</option>";
        echo "</select><br><br>";
        echo "</fieldset>";

        echo "<fieldset><legend><b>Special Options</b></legend>";
        echo "<input type=\"checkbox\" name=\"special\" value=\"flip_table\"> Flip Table<br><br>";
        echo "<input type=\"submit\" name=\"submitRec\" value=\"Submit\"/>";         
        echo "</fieldset>";

        if(isset($_POST['submitRec']))
        {
            print "<script language=\"javascript\">window.alert('test')</script>";

        }
        echo "</form>";  
        echo "</div>";

    }

}
?>

Edited by diafol: Not a snippet - just an thread article

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by mmcdonald
1

Well your if(isset($_POST['submitRec'])) is inside your if(isset($_POST['submitButton'])) statement, so in order for it to work, $_POST['submitButton'] must be set. This is probably not the case when you submit the second form, so what I think should solve your problem is placing the if() construction that contains the Javascript warning outside its parent if() construction :).

Edited by minitauros

Votes + Comments
Thanks it worked :)
0

You'reDon't you think you're better off storing the values from form one and when it's submitted reloading the page with form 2? Perhaps by setting a session or rewriting the URL to domain.com/page.php?form=2

What you have right now will not work as your isset is within another isset at Minitauros said about :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.