LinuxGuruz
Toll Free Numbers
Custom Search
MAIN MENU
Main Page
IT Jobs
IPTABLES
Linux Forum
HTML Forum
PHP Forum
MySQL Forum
Linux FAQ
Linux Articles
About Us
Privacy Policy

ADD TO FAVORITES


MARC

Mailing list ARChives
- Search by -
 Subjects
 Authors
 Bodies





FOLDOC

Computing Dictionary






Cheap UK Web Hosting Provider

Cheap Dedicated Servers UK

Cheap Linux VPS Hosting UK

Cheap Cloud Hosting UK



Icons
Icons


free brochure template
Free Brochure Template

Web Hosting

Domain Names

Web Design

Reseller Hosting

Registro de Dominios

Reseller Hosting


Toll Free Number for $2.00/Month!!!

Toll Free Number for $2.00/Month!!!
PHP FORM Tips

Title:       PHP FORM Tips
Contributor: Randall Goguen (aka Ranman)
Last Update: Tuesday June 25 13:10 am EDT 2002


Example 1:

<?
if (!isset($pick)) {
echo "Fill out and submit the form below."; }
else {
$j = count($pick);
for($i=0; $i<$j; $i++) {
echo "Pick <b>$pick[$i]</b> is Checked<br />"; }
}
?>

<form action="<? echo $PHP_SELF; ?>">
<ol>
<li>Painting<input name="pick[]" type=checkbox value="Painting" /></li>
<li>Plumbing<input name="pick[]" type=checkbox value="Plumbing" /></li>
<li>Electric<input name="pick[]" type=checkbox value="Electric" /></li>
</ol>

<input type="submit" value="Submit!" />
<input type="reset" value="Reset" />
</form>
Demo!

Example 2:

<?
if (!isset($Categorys)) {
echo "Fill out and submit the form below."; }
else {
$j = count($Categorys);
for($i=0; $i<$j; $i++) {
echo "Category <b>$Categorys[$i]</b> is Checked<br />"; }
}
?>

<form action="<? echo $PHP_SELF; ?>">
<select name="Categorys[]" multiple>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<p />
<input type="submit" value="Submit!" />
<input type="reset" value="Reset" />
</form>
Demo!


Example 3:

<?
$today = date("l dS of F Y h:i a");
print "<CENTER><B>Today is $today</B></CENTER>";
$year = 2001;
if (isset($month)) {
echo "You selected <B>$month</B>";
} ?>
<P>
<FORM ACTION="<? echo $PHP_SELF; ?>">
<SELECT NAME="month">
<?
for ($i=1; $i<=12; $i++) {
$this_month = date("F", mktime(0,0,0,$i,1,2001)); ?>
<OPTION value="<? echo $this_month; ?>"><? echo $this_month; ?>
<? } ?>
</SELECT>
<P>
<input type="submit" value="Submit!" />
<input type="reset" value="Reset" />
</FORM>
Demo!


Example 4:

<?
$today = date("l dS of F Y h:i a");
print "<CENTER><B>Today is $today</B></CENTER>";
$year = 2001;
if (isset($month)) {
echo "You selected <B>
$month $day $hour:$minute $am_pm
</B><P><B>$message</B>";
} ?>
<P>
<FORM ACTION="<? echo $PHP_SELF; ?>" METHOD="post">
Month <SELECT NAME="month" SIZE="3">
<? for ($i=1; $i<=12; $i++) {
$j = date("F", mktime(0,0,0,$i,1,$year));
echo "<OPTION value=\"$j\" SELECTED>$j";
} ?>
</SELECT>
Day <SELECT NAME="day" SIZE="3">
<? for ($i=1; $i<=31; $i++) {
$i = sprintf("%02d", $i);
echo "<OPTION value=\"$i\" SELECTED>$i";
} ?>
</SELECT>
Time <SELECT NAME="hour" SIZE="3">
<? for ($i=1; $i<=12; $i++) {
$i = sprintf("%02d", $i);
echo "<OPTION value=\"$i\" SELECTED>$i";
} ?>
</SELECT><B>:</B><SELECT NAME="minute" SIZE="3">
<? for ($i=0; $i<=59; $i++) {
$i = sprintf("%02d", $i);
echo "<OPTION value=\"$i\" SELECTED>$i";
} ?>
</SELECT>
<SELECT name="am_pm">
<OPTION value="am">am
<OPTION value="pm">pm
</SELECT>
<P>
Message
<TEXTAREA name="message" cols="40" rows="8" wrap="PHYSICAL">
</TEXTAREA>
<P>
<input type="submit" value="Submit!" />
</FORM>

Demo!


Example 5:

<?
if (isset($subject)) { echo "$subject[0]<br />";
echo "$subject[1]<p />"; }
else { $subject[0] = "Enter Subject A";
$subject[1] = "Enter Subject B"; } ?>
<FORM ACTION="<? echo $PHP_SELF; ?>">
<input type="text" NAME="subject[0]" value="<? echo $subject[0]; ?>" />
<input type="text" NAME="subject[1]" value="<? echo $subject[1]; ?>" />
<input type="submit" value="Submit!" />
<input type="reset" value="Reset" />
</FORM>


Demo!


Example 6:

<?
if (!isset($pick)) {
echo "Fill out and submit the form below."; }
else {
$j = count($pick);
for($i=0; $i<$j; $i++) {
echo "Pick <B>$pick[$i]</B> is Checked<br />"; }
}
?>
<P>
<FORM ACTION="<? echo $PHP_SELF; ?>">
<OL>
<LI>Business<INPUT NAME="pick[]" TYPE=radio value="Business">
<LI>Education<INPUT NAME="pick[]" TYPE=radio value="Education">
<LI>Employment<INPUT NAME="pick[]" TYPE=radio value="Employment">
</OL>

<input type="submit" value="Submit!" />
<input type="reset" value="Reset" />
</FORM>

Demo!


Example 7:

<?
if (isset($clicked)) { echo "$clicked"; }
else { echo "Please Select 1, 2 or 3"; }
?>
<p />
<form>
<input type="submit" name="clicked" value="1" />
<input type="submit" name="clicked" value="2" />
<input type="submit" name="clicked" value="3" />
<input type="reset" value="Reset" />
</form>
Demo!


Example 8:

<? if (isset($clicked)) {
if ($clicked == "1") { echo "my_function_1();"; }
elseif ($clicked == "2") { echo "my_function_2();"; }
else { echo "my_function_3();"; }
} else { echo "Please Select 1, 2 or 3"; } ?>
<p /><form>
<input type="submit" name="clicked" value="1" />
<input type="submit" name="clicked" value="2" />
<input type="submit" name="clicked" value="3" />
</form>
Demo!


Example 9:

<form action="<?= $PHP_SELF ?>">
<?
if (!isset($subject)) {
echo "Fill out and submit the form below.<P>"; }
if (!isset($subject[0]) || $subject[0] == ""
 || $subject[0] == "Enter your Full Name") {
$subject[0] = "Enter your Full Name"; echo ?>
<input type="text" NAME="subject[0]"
 value="<?= $subject[0] ?>" SIZE="50" /><br />
<? } else { echo ?>
<input type="hidden" NAME="subject[0]" value="<?= $subject[0] ?>" />
<? } if (!isset($subject[1]) || $subject[1] == ""
 || $subject[1] == "Enter your Street Address") {
$subject[1] = "Enter your Street Address"; echo ?>
<input type="text" NAME="subject[1]"
 value="<?= $subject[1] ?>" SIZE="50" /><br />
<? } else { echo ?>
<input type="hidden" NAME="subject[1]" value="<?= $subject[1] ?>" />
<? } if (!isset($subject[2]) || $subject[2] == ""
 || $subject[2] == "Enter your E-Mail Address") {
$subject[2] = "Enter your E-Mail Address"; echo ?>
$subject[2] = "Enter your E-Mail Address"; echo ?>
<input type="text" NAME="subject[2]"
 value="<?= $subject[2] ?>" SIZE="50" /><p />
<? } else { echo ?>
<input type="hidden" NAME="subject[2]" value="<?= $subject[2] ?>" />
<? }
if ($subject[0] == "Enter your Full Name" ||
$subject[1] == "Enter your Street Address" ||
$subject[2] == "Enter your E-Mail Address") { echo ?><P>
<input type="submit" value="Submit!" /><input type="reset" value="Reset" />
<? } else { echo "Thank You $subject[0]!"; } ?>
</form>

Demo!


Example 10:

# Drop down files in a directory from newest to oldest. <? $dir = "/home/ranman/linuxguruz.org/htdocs/downloads" ?> <? $this = nl2br(`ls -lt $dir | grep "^-" | awk '{print $9;}'`) ?> <? $that = split("<br>", $this) ?> <FORM ACTION="<? echo $PHP_SELF; ?>"> <SELECT NAME="file_name"> <? $j = count($that); for ($i=1; $i<$j; $i++) { ?> <OPTION value="<?= $that[$i] ?>"><?= $that[$i] ?><? } ?></SELECT> <P><input type="submit" value="Submit!" /> </FORM>

Demo!


Example 11:

<?
if (isset($button)) { echo key($button); }
else { echo "Please make a Selection"; }
?>
<P><form action="<? echo $PHP_SELF; ?>">
<input type="submit" NAME="button[0]" value="Apply" />
<input type="submit" NAME="button[1]" value="Apply" />
<input type="submit" NAME="button[2]" value="Apply" />
</FORM>

Demo!


Example 12:

<?
Header("Cache-Control: no-cache");
Header("Pragma: no-cache");
?>
<?
$os_name = array("Linux", "Windows", "Macintosh");
if (!isset($os)) {
echo "Fill out and submit the form below."; }
else {
$j = count($os);
for($i=0; $i<$j; $i++) {
echo "OS <B>$os[$i]</B> is Checked<BR>"; }
}
?>
<form action="<? echo $PHP_SELF; ?>">
<select name="os[]" multiple>
<?
$k = 0;
$j = count($os_name);
for($i=0; $i<$j; $i++) { ?>
<option value="<?= $os_name[$i] ?>"
<? if (isset($os[$k]) && $os_name[$i] == $os[$k]) {
echo "selected"; $k++; } ?>>
<?= $os_name[$i]; } ?>
</select><p>
<input type="submit" value="Submit!">
<input type="reset" value="Reset">
</form>

Demo!

See Also: Securing file uploads under PHP


        Anyone who wishes to make additions or changes to this
PHP Tutorial email them to webmaster@linuxguruz.org

        This document is Copyright (c) 1999, 2000, 2001 by LinuxGuruz

Return to the LinuxGuruz PHP Tutorials Page
Return to the LinuxGuruz Main Page


www.PHP.net Search Engine


Restrict the search to:
Copyright © 1999, 2000 The PHP Development Team.
Submit a PHP Tutorial

Title:

Contributor:

IRC NICK: (optional)

E-Mail Address: (optional)

Tutorial:

Return to the LinuxGuruz PHP Tutorials Page
Return to the LinuxGuruz Main Page

RESOURCE LINKS
Linux
Apache
HTML
PHP
MySQL
PostgreSQL
Oracle
CGI
Perl
Java
C/C++
Bash
Tcl
Networking
Security
ISP
IRC
Xwindow
Laptop
Graphics
Hardware
Reference
Misc

Broadband


filing cabinet

  • Buy Batteries for Laptops and Cameras
  • Notebooks
  • Michael Fertik
  • Reputation Defender

  • XP Style Icons
    XP Style Icons


    Network Certification


    Network Security


    Wireless Networking


    Canadian
    Web Hosting in Canada


    Drummer Portal


    Mending Media

    The Path Of
    Most Resistance


    Toll Free Number for $2.00/Month!!!

    Toll Free Number for $2.00/Month!!!


    Linux

    The Distributions





    Linux

    The Software





    Linux

    The News




    webmaster@linuxguruz.com
    Copyright © 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 and 2009 by LinuxGuruz