Page 1 of 1

PHP forms

Posted: Sat Nov 26, 2005 10:19 am
by InnerShadow
I was wondering if there was any way to do and IF/ELSE statement that, if true would print a form for the viewer? An Example would be great

Posted: Sat Nov 26, 2005 11:54 am
by ody

Code: Select all

if(1)
{
	echo '<form><input type="text"></form>';
}
else
{
	echo 'no form for you';
}

Posted: Sat Nov 26, 2005 11:59 am
by foobar
Answer: yes.

Example:

Assuming a form is submitted to this page via POST

Code: Select all

<?php

if ($_SERVER['REQUEST_METHOD'] != 'POST') { //<-- modify condition as you see fit

  //do some fancy stuff...
  exit; //<-- kills the script so that the form isn't shown
}

?>
<form action="" method=""><!----></form>
I purposefully put in an exit; instead of an else {} so that you don't have to close it at the end of the script.