scripting process doesn't function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
 
I have made some script that process the users input, and validates the input and sends it back. But it doesn't work very
well, in fact it doesn't work at all. I am only able to see and input my name and such in the html form, but the php part doesn't do it's job.
I have looked over the scripts thousands of times, but couldn't find the problem, really.
 
Here is the script plus 2 .inc files;
 
Hoping for some replies and answers,
Thanks in advance!
 
PS: if this script is a bit messy to read, I have included them in this mail seperately.
 
 
<?php
/* Script name:  addressForm.inc
 * Description: Script displays a form.
 */
 
   echo "<html>
    <head><title>Customer Address</title></head>
    <body>";
 echo "<p align='center'>
    <form action='' method='POST'>
    <table width='95%' border='0' cellspacing='0'
        cellpadding='2'\n";
 foreach($labels as $field=>$value)
 {
  if(isset($_POST[$field]))
  {
   $value = $_POST[$field];
  }
  else
  {
   $value = "";
  }
  echo "<tr><td align='right'>{$labels[$field]}</br></td>
     <td><input type='text' name'$field' size='65'
        maxlength='65'
      value='$value'> </td> </tr>";
 }
 echo " </table>
     <div align='center'>
       <p><input type='Submit' name='Submit'
      value='Submit Address'></p></div>
     </form>";
?>
</body></html>
 
 
 
 
<?php
/* Script name:  info.inc
 * Description:  creates an array of labels for use in a
 *     form.
 */
 $labels = array( "firstName"=>  "First Name:",
      "midName"=>"Middle Name:",
      "lastName"=>"Last Name:",
      "street"=>"Street Address:",
      "city"=>"City:",
      "state"=>"State:",
      "zipcode"=>"Zipcode:");
     
?>
 
 
 
<?php
/* Script name:  validateForm
 * Description: Displays and validates a form that
 *     collects a name and address.
 */
 
  include("info.inc");         #6
  #################################
  ## First display of empty form ##
  #################################
  if(!isset($_POST['Submit']))        #10
  {
   include("addressForm.inc");
  }
  ########################################################
  ## Check information when form is submitted. Build ##
  ## arrays of blank and incorrectly formatted fields. ##
  ## If any errors are found, display error messages ##
  ## and redisplay form. If no errors found, display ##
  ## the submitted information.    ##
  ########################################################
   else           #21
   {
     foreach($_POST as $field=>$value)      #23
   {
    if(empty($_POST[$field]))      #25
  {
     if($field !="midName")
     {
        $blanks[$field] = "blank";     #29
     }
  }
  else         #33
  {
   $value = trim($value);
   if($field != "zipcode")
   {
    if(!ereg("^[A-Za-z0-9' .-]{1,65}$",$value))
    {
     $formats[$field] = "bad";
    }
   }
   elseif($field == "zipcode")
   {
    if(!ereg("^[0-9]{5}(\-[0-9]{4})?",$value))
    {
      $formats[$field] = "bad";
    }
   }
  }
 }          #51
 ### if any fields were not okay, display error ###
 ### message and redisplay form         ###
 if (@sizeof($blanks) > 0 or @sizeof($formats) > 0)    #54
 {
   if (@size($blanks) > 0)
   {
     echo "<b>You didn't fill in one or more
     required fields. You must enter:</b><br>";
  foreach($blanks as $field => $value)
  {
    echo "&nbsp;&nbsp;&nbsp;{$labels[$field]}<br>";
  }
 }
 if (@sizeof($formats) > 0)
 { 
   echo "<b>One or more fields have information that
        appears to be incorrect. Correct the
      format for:</b><br>";
   foreach($formats as $field => $value)
   {
     echo "&nbsp;&nbsp;&nbsp;{$labels[$field]}<br>";
   }
 }
 echo "<hr>";
 include("adressForm.inc");
  }
  else
  {
     ### If no errors in the form, display the  ###
 ### name and address submitted by user ###
  echo "<html><head><title>Name and Address
    </title></head><body>\n";
  foreach($_POST as $field=>$value)
  {
   if($field != "Submit")
  {
    echo "{$labels[$field]} $value<br>\n";
   }
  }
  echo "</body></html>";
 }
   } 
?>
 


Met MSN Spaces kun je per e-mail je weblog bijwerken. Publiceer leuke verhalen, foto's en meer! Het is gratis! Het is gratis!
<?php
/*	Script name: 	addressForm.inc
 *	Description:	Script displays a form.
 */
  
  	echo "<html>
		  <head><title>Customer Address</title></head>
		  <body>";
	echo "<p align='center'>
		  <form action='validateForm.php' method='POST'>
		  <table width='95%' border='0' cellspacing='0'
		  				cellpadding='2'\n";
	foreach($labels as $field=>$value)
	{
		if(isset($_POST[$field]))
		{
			$value = $_POST[$field];
		}
		else
		{
			$value = "";
		}
		echo "<tr><td align='right'>{$labels[$field]}</br></td>
			  <td><input type='text' name'$field' size='65'
			  			maxlength='65'
						value='$value'> </td> </tr>";
	}
	echo " </table>
		   <div align='center'>
		   	 <p><input type='Submit' name='Submit'
			 		value='Submit Address'></p></div>
		   </form>";
?>
</body></html>
<?php
/* Script name: 	info.inc
 * Description:		creates an array of labels for use in a 
 *					form.
 */

	$labels = array( "firstName"=>	 "First Name:",
					 "midName"=>"Middle Name:",
					 "lastName"=>"Last Name:",
					 "street"=>"Street Address:",
					 "city"=>"City:",
					 "state"=>"State:",
					 "zipcode"=>"Zipcode:");
					 
?>				 
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux