PHP forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

PHP forms

Post 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
ody
Forum Contributor
Posts: 147
Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK

Post by ody »

Code: Select all

if(1)
{
	echo '<form><input type="text"></form>';
}
else
{
	echo 'no form for you';
}
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
Post Reply