Nodoid Nodoid - 1 month ago 15
HTML Question

Unable to use echo with php form

My PHP form seems to be operating fine. The page comes up and when I click on the submit button, the isset($_POST['submitted']) condition at the start is hit and the code run.

The only issue is that I have a couple of echo lines in the code to produce a JS alert box. Neither seem to be getting called. I'm not sure that the external PHP functions are being called either as I have no way of testing the value returned.

My PHP looks like this

<?php if (isset($_POST['submitted'])) {
$output = checkData();
if ($output != "done")
{
echo '<script type="text/javascript">alert("' . $output . '"); </script>';
}
else
{
createMeeting();
echo '<script type="text/javascript">alert("You meeting has been created. All of the recipients should shortly receive an email"); </script>';
header('Location: index.php');
}
} else { ?>
<center>
<form method="POST" action="">
...
<input type="submit" name="submitted" value="Create Meeting">
</form>
<?php
}
?>


My checkData() function simply checks to see if the other parts of the form data are empty and exit with either "done" (no errors) or a message if one of the form elements is empty.

createMeeting() will create a meeting based on the data and submit it to my server - currently, it takes the same data as checkData() and then returns.

Both functions come back with no errors when I run it through an online PHP code checker.

Answer

I've tried your code and it seems to work fine in my case.

<?php if (isset($_POST['submitted'])) {
$output = "done"; //even if this line is not equal to 'done', the code still works fine
if ($output != "done")
{
    echo '<script type="text/javascript">alert("' . $output . '");</script>';
}
else
{
    //    createMeeting();
    echo '<script type="text/javascript">alert("You meeting has been created. All of the recipients should shortly receive an email"); </script>';
    //    header('Location: index.php');
}
} else { ?>
    <center>
    <form method="POST" action="">
    ...
    <input type="submit" name="submitted" value="Create Meeting">
    </form>
<?php
}
?>

So to my knowledge, there're errors with your createMeeting() or checkData() functions. Can you please be more specific with the error messages (if any)?