| This example shows a very simple form together with the form handling process on a single page. <?php
//check if the submit variable exists
if ($_POST['Submit']) {
$mytext=$_POST['mytext'];
echo "<BR>got submission<BR>";
echo "<BR> you entered: $mytext<BR>";
//process form action
} else { //no form has been submitted, so display the form
?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input name="mytext" type="text" id="mytext">
<input type="submit" name="Submit" value="Submit">
</form>
<?
}
?>
Below is another approach based on Heredoc I like:
<?php
//check if the submit variable exists
if ($_POST['Submit']) {
$mytext=$_POST['mytext'];
echo "<BR>got submission<BR>";
echo "<BR> you entered: $mytext<BR>";
//process form action
} else { //no form has been submitted, so display the form
echo <<< HTML_TAG
<form name="form1" method="post" action="{$_SERVER['PHP_SELF']}">
<input name="mytext" type="text" id="mytext">
<input type="submit" name="Submit" value="Submit">
</form>
HTML_TAG;
}
?> |