• BOOKMARK

  • ADD TO FAVORITES

  • REFERENCES


  • MARC

    Mailing list ARChives
    - Search by -
     Subjects
     Authors
     Bodies





    FOLDOC

    Computing Dictionary




  • Text Link Ads






PHP FORM Tips

PHP Tutorials.

PHP FORM Tips

New postby Ranman on Thu Mar 27, 2008 10:39 pm

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! --->http://www.linuxguruz.org/tutorials/33Demo.php


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! --->http://www.linuxguruz.org/tutorials/33Demo2.php


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! --->http://www.linuxguruz.org/tutorials/33Demo3.php


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! --->http://www.linuxguruz.org/tutorials/33Demo4.php


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! --->http://www.linuxguruz.org/tutorials/33Demo5.php


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! --->http://www.linuxguruz.org/tutorials/33Demo6.php


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! --->http://www.linuxguruz.org/tutorials/33Demo7.php


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! --->http://www.linuxguruz.org/tutorials/33Demo8.php


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! --->http://www.linuxguruz.org/tutorials/33Demo9.php


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! --->http://www.linuxguruz.org/tutorials/33Demo10.php


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! --->http://www.linuxguruz.org/tutorials/33Demo11.php


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! --->http://www.linuxguruz.org/tutorials/33Demo12.php


See Also: Securing file uploads under PHP:
User avatar
Ranman
Site Admin
 
Posts: 25
Joined: Thu Mar 27, 2008 12:27 am

Re: PHP FORM Tips

New postby Joplin on Mon Dec 23, 2013 12:28 pm

PHP Offical Documentation
Dealing with Forms
User avatar
Joplin
 
Posts: 12
Joined: Tue Apr 01, 2008 12:34 am


Return to PHP Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

  • MORE RESOURCE


  • Linux

    The Distributions





    Linux

    The Software





    Linux

    The News



  • MARKETING






  • Toll Free
cron