Responding To Checkboxes

  <html> <head> <title>Checkbox Demo</title> </head> <body> <h1>Checkbox Demo</h1><h3>Demonstrates checkboxes</h3> <form action ="HandleFormCheckBox.php"><ul> <li><input type ="checkbox" name ="chkFries" value ="11.00">Fries</li> <li><input type ="checkbox" name ="chkSoda" value ="12.85">Soda</li> <li><input type ="checkbox" name ="chkShake" value ="1.30">Shake</li> <li><input type ="checkbox" name ="chkKetchup" value =".05">Ketchup</li> </ul> <input type ="submit"> </form></body> </html><!– HandleFormCheckBox.php <html> <head> <title>Checkbox Demo</title> </head> <body> <h3>Demonstrates […]
Continue reading…

Enjoyed this post? Share it!

 
 

Saying “Hello”

  <? if (array_key_exists(’my_name’,$_POST)) { print "Hello, ". $_POST[’my_name’]; } else { print<<<_HTML_ <form method="post" action="$_SERVER[PHP_SELF]"> Your name: <input type="text" name="my_name"> <br/> <input type="submit" value="Say Hello"> </form> _HTML_; } ?>
Continue reading…

Enjoyed this post? Share it!

 
 

Send Email With Cc And Bcc

  <html> <head> <title>Send email with CC and BCC</title> </head> <body> <form action="sendemailWithCC_BCC.php" method=post name=form1> <table> <tbody> <tr> <td> <div align=right><b>To</b></div></td> <td> <p>Name <input name=mailtoname size=35><br />E-mail <input name=mailtomail size=35></p></td></tr> <tr> <td> <div align=right><b>CC</b></div></td> <td><input name=mailcc size=35> </td></tr> <tr> <td> <div align=right><b>BCC</b></div></td> <td><input name=mailbcc size=35> </td></tr> <tr> <td> <div align=right><b>Priority</b></div></td> <td><select name=mailpriority> <option value=1>Highest</option> <option […]
Continue reading…

Enjoyed this post? Share it!

 
 

Set Cookie Data

  <?php $user = $_POST[’user’]; $color = $_POST[’color’]; $self = $_SERVER[’PHP_SELF’]; if( ( $user != null ) and ( $color != null ) ) { setcookie( "firstname", $user , time() + 36000 ); setcookie( "fontcolor", $color, time() + 36000 ); header( "Location:getcookie.php" ); exit(); } ?><html> <head> <title>Set Cookie Data</title> </head> <body> <form action ="<?php […]
Continue reading…

Enjoyed this post? Share it!

 
 

Simple File Upload Form

  <html> <head> <title>A Simple File Upload Form</title> </head> <body> <form enctype="multipart/form-data" action="<?print $_SERVER[’PHP_SELF’]?>" method="post"> <p> <input type="hidden" name="MAX_FILE_SIZE" value="102400" /> <input type="file" name="fupload" /><br/> <input type="submit" value="upload!" /> </p> </form> </body> </html>
Continue reading…

Enjoyed this post? Share it!

 
 

Uploading A File

  <?php if ($_SERVER[’REQUEST_METHOD’] == ‘GET’) { ?> <form method="post" action="<?php echo $_SERVER[’SCRIPT_NAME’] ?>" enctype="multipart/form-data"> <input type="file" name="document"/> <input type="submit" value="Send File"/> </form> <?php } else { if (isset($_FILES[’document’]) && ($_FILES[’document’][’error’] == UPLOAD_ERR_OK)) { $newPath = ‘/tmp/’ . basename($_FILES[’document’][’name’]); if (move_uploaded_file($_FILES[’document’][’tmp_name’], $newPath)) { print "File saved in $newPath"; } else { print "Couldn’t move file […]
Continue reading…

Enjoyed this post? Share it!

 
 

Using Arrays With Form Data In Php

  <select NAME="myselect[]" MULTIPLE SIZE=3> <option VALUE="value1">A</option> <option VALUE="value2">B</option> <option VALUE="value3">C</option> <option VALUE="value4">D</option> </select>//The PHP code to access which value(s) were selected:<?php foreach($_GET[’myselect’] as $val) { echo "You selected: $val<br />"; } echo "You selected ".count($_GET[’myselect’])." Values."; ?>
Continue reading…

Enjoyed this post? Share it!

 
 

Passing Complex Values In A Querystring

  string serialize ( mixed value ) mixed unserialize ( string str ) <html> <?php class someclass { protected $someval; public function setsomeval($newval) { $this->someval = $newval; } public function getsomeval() { return $this->someval; } } $myclass = new someclass ( ); $myclass->setsomeval ( "Hello World!" ); $myarray = array (); $myarray [0] = "Hello";$myarray […]
Continue reading…

Enjoyed this post? Share it!

 
 

Validating Form Data

  <? if ($_POST[’_submit_check’]) { if (validate_form()) { process_form(); } else { show_form(); } } else { show_form(); }function process_form() { print "Hello, ". $_POST[’my_name’]; }function show_form() { print<<<_HTML_ <form method="POST" action="$_SERVER[PHP_SELF]"> Your name: <input type="text" name="my_name"> <br/> <input type="submit" value="Say Hello"> <input type="hidden" name="_submit_check" value="1"> </form> _HTML_; }function validate_form() { if (strlen($_POST[’my_name’]) < 3) […]
Continue reading…

Enjoyed this post? Share it!

 
 

Passing Numeric Values In A Querystring

  <html> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <div align="center"> <p>Click a link to change the text color of the verbiage below:</p> <a href="index.php?color=1">Green</a><br /> <a href="index.php?color=2">Red</a><br /> <a href="index.php?color=3">Blue</a><br /> <a href="index.php">Reset</a> <?php if (isset ($_GET[’color’])){ $color = intval ($_GET[’color’]); } else { $color = ""; } if ($color == 1){ $fontcolor […]
Continue reading…

Enjoyed this post? Share it!

 
 

Elementary Form Validation

  <?php if(isset($_GET[’submit’])) { if(preg_match("/^\(([2-9][0-9]{2})\)[2-9][0-9]{2}-[0-9]{4}$/i", $_GET[’phone’]) != 1) { echo "The phone field was invalid<br />"; } } else { /* Code to process form here */ } ?> <html> <head><title>Elementary form validation</title></head> <body> <form ACTION="<?php echo $_SERVER[’PHP_SELF’]; ?>" METHOD=GET> <input TYPE="hidden" NAME="submit" VALUE="1"> Phone: <input TYPE="text" NAME="phone" SIZE=13 MAXLENGTH=13> (ex. (333)555-1212)<br /> <input TYPE="submit" […]
Continue reading…

Enjoyed this post? Share it!

 
 

A Form With Checkboxes Using The Same Name To Store Multiple Values

  <html> <head> <title>Using Default Checkbox Values</title> </head> <body> <?php $food = $_GET["food"]; if (!empty($food)){ echo "The foods selected are: <strong>"; foreach($food as $foodstuff){ echo ‘<br />’.htmlentities($foodstuff); } echo "</strong>."; } else { echo (’ <form action="’. htmlentities($_SERVER["PHP_SELF"]).’" method="GET"> <fieldset> <label> Italian <input type="checkbox" name="food[]" value="Italian" /> </label> <label> Mexican <input type="checkbox" name="food[]" value="Mexican" /> […]
Continue reading…

Enjoyed this post? Share it!

 
 

Form Data Validation With Error Count

  <html> <body> <form METHOD="POST" ACTION="FormDataValidationWithErrorCount.php"> <h1>Contact Information</h1> <table><tr> <td><b>Nickname:</b></td> <td><input TYPE="TEXT" NAME="nickname"></td> </tr><tr> <td><b>First Name:</b></td> <td><input TYPE="TEXT" NAME="firstname"></td> </tr><tr> <td>Middle Name:</td> <td><input TYPE="TEXT" NAME="middlename"></td> </tr><tr> <td><b>Last Name:</b></td> <td><input TYPE="TEXT" NAME="lastname"></td> </tr><tr> <td><b>Primary Email:</b></td> <td><input TYPE="TEXT" NAME="email"></td> <td WIDTH="20">&nbsp;</td> <td>Secondary Email:</td> <td><input TYPE="TEXT" NAME="secondaryemail"></td> </tr><tr> <td></td> <td><input TYPE="TEXT" NAME="officeaddress2"></td> </tr><br /> <br /> <br /> […]
Continue reading…

Enjoyed this post? Share it!

 
 

An Html Form That Calls Itself

  <html> <head> <title>An HTML Form that Calls Itself</title> </head> <body> <div> <?php if ( ! empty( $_POST[’guess’] ) ) { print "last guess: ".$_POST[’guess’]; } ?> <form method="post" action="<?php print $_SERVER[’PHP_SELF’]?>"> <p> Type your guess here: <input type="text" name="guess" /> </p> </form> </div> </body> </html>
Continue reading…

Enjoyed this post? Share it!

 
 

Form Example For The Form Validator Script

  <?php if($form_errors): ?> <ul> <?php foreach($form_errorlist as $val): ?> <li><?php echo $val;?> <?php endforeach; ?> </ul> <?php endif; ?>Please fill out the following form (* = Required)<br /> <form ACTION="<?php echo $_SERVER[’PHP_SELF’]; ?>" METHOD=GET> <input TYPE="hidden" NAME="submit" VALUE="1"> <input TYPE="hidden" NAME="required" VALUE="phone,email,fax"> <input TYPE="hidden" NAME="phone_desc" VALUE="Phone Number"> <input TYPE="hidden" NAME="email_desc" VALUE="Email Address"> <input TYPE="hidden" […]
Continue reading…

Enjoyed this post? Share it!

 
 

A Php Number-Guessing Script

  <?php $num_to_guess = 42; $message = ""; if ( ! isset( $_POST[’guess’] ) ) { $message = "Welcome!"; } else if ( $_POST[’guess’] > $num_to_guess ) { $message = $_POST[’guess’]." is too big!"; } else if ( $_POST[’guess’] < $num_to_guess ) { $message = $_POST[’guess’]." is too small!"; } else { $message = "Well […]
Continue reading…

Enjoyed this post? Share it!

 
 

Form Value Validation: Not Empty

  <html> <body> <form METHOD="POST" ACTION="FormErrorCheck.php"> <h1>Contact Information</h1> <table><tr> <td><b>Nickname:</b></td> <td><input TYPE="TEXT" NAME="nickname"></td> </tr><tr> <td>Title:</td> <td><input TYPE="TEXT" NAME="title"></td> </tr><tr> <td><b>First Name:</b></td> <td><input TYPE="TEXT" NAME="firstname"></td> </tr><tr> <td>Middle Name:</td> <td><input TYPE="TEXT" NAME="middlename"></td> </tr><tr> <td><b>Last Name:</b></td> <td><input TYPE="TEXT" NAME="lastname"></td> </tr><tr> <td><b>Primary Email:</b></td> <td><input TYPE="TEXT" NAME="email"></td> <td WIDTH="20">&nbsp;</td> <td>Secondary Email:</td> <td><input TYPE="TEXT" NAME="secondaryemail"></td> </tr><tr> <td>Company Name:</td> <td><input TYPE="TEXT" NAME="companyname"></td> […]
Continue reading…

Enjoyed this post? Share it!