Re: Create mail/contact form
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Create mail/contact form

From: Steve <googlespam@nastysoft.com>
Date: Tue Jul 19 2005 - 14:39:42 CEST

Stephanie wrote:
> But how can i display error messages (e.g. empty field), in this (same)
> form. (e.g. at the top of the page)

Depends on how your PHP code is arranged, but here is one way to
achieve this - a simple form with only one field:

<?php

   $strError = ''; // assume no errors
   $strName = '';

   if( isset( $_POST[ 'Name' ] ) )
   {
      // validate 'Name'...
      $strName = $_POST[ 'Name' ];
      if( strlen( $strName ) < 10 )
      {
         $strError = 'ERROR: Name must be at least 10 characters<br
/>';
      }
      if( $strName == 'Steve' )
      {
         $strError = 'ERROR: Your name is Steve<br />';
      }
      // ... etc ...
   }
   else
   {
      // nothing filled in yet...
      $strError = 'Please fill in all of the following values<br />';
   }

   if( $strError == '' )
   {
      // ... all ok, process the form ...
   }
   else
   {
      // print the form (again) with any user-supplied values filled
in...
      // include error report above the form...

?>

<form method="post" action="...">
<?php print $strError; ?>
Name: <input name="Name" type="text" value="<?php print $strName; ?>"
/>
<input name="Save" type="submit" value=" Save " />
</form>

<?php

   }

?>

---
Steve
Received on Mon Oct 17 21:10:46 2005