Jump to content

how to configure forms using PHP


djcrisp22

Recommended Posts

<form action="simple.php" method="POST">
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">

<tr><td>First Name:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Address:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>City:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>State:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Zip:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Phone number:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Email address:</td><td><input type="text" name="name" size="25" /></td></tr>


<tr>
<td align="center" colspan="2">
<input type="submit" value="Submit" /><br />

</td>
</tr>
</table>
</form>

 

how do i create a php script to save it to a linux server or post the messages on the browser? also, is there a way when a user click submit button and then the user is redirected to another page??? can anyone help?? thanks in advance :-)

Link to comment
https://forums.phpfreaks.com/topic/126307-how-to-configure-forms-using-php/
Share on other sites

<form action="simple.php" method="POST">
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">

<tr><td>First Name:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Address:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>City:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>State:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Zip:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Phone number:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Email address:</td><td><input type="text" name="name" size="25" /></td></tr>


<tr>
<td align="center" colspan="2">
<input type="submit" value="Submit" /><br />

</td>
</tr>
</table>
</form>

 

how do i create a php script to save it to a linux server or post the messages on the browser? also, is there a way when a user click submit button and then the user is redirected to another page??? can anyone help?? thanks in advance :-)

 

how can i tweak this code to make it work with my html form?? i am not sure what to add into the script?? thanks in advance :D

   1.
      <?php
   2.
      // Function to display form
   3.
      function showForm($errorName=false,$errorEmail=false,$errorMesg=false){
   4.
      if ($errorName) $errorTextName = "Please enter your name!";
   5.
      if ($errorEmail) $errorTextEmail = "Please enter a valid email address!";
   6.
      if ($errorMesg) $errorTextMesg = "Please leave a longer message!";
   7.
       
   8.
      echo '<form action="form.php" method="POST"><table>';
   9.
       
  10.
      // Display name field an error if needed
  11.
      echo '<tr><td>Name:</td><td><input type="text" name="name"></td></tr>';
  12.
      if ($errorName) echo "<tr><td colspan='2'>$errorTextName</td></tr>";
  13.
       
  14.
      // Display email field an error if needed
  15.
      echo '<tr><td>Email:</td><td><input type="text" name="email"></td></tr>';
  16.
      if ($errorEmail) echo "<tr><td colspan='2'>$errorTextEmail</td></tr>";
  17.
       
  18.
      // Display message field an error if needed
  19.
      echo '<tr><td>Message:</td><td><textarea name="mesg"></textarea></td></tr>';
  20.
      if ($errorMesg) echo "<tr><td colspan='2'>$errorTextMesg</td></tr>";
  21.
       
  22.
       
  23.
      echo '<tr><td><input type="submit" name="SubmitForm" value="Send"></td></tr>';
  24.
      echo '<form>';
  25.
      }
  26.
       
  27.
       
  28.
      if (!isset($_POST['SubmitForm'])) {
  29.
      showForm();
  30.
      } else {
  31.
      //Init error variables
  32.
      $errorName = false;
  33.
      $errorEmail = false;
  34.
      $errorMesg = false;
  35.
       
  36.
      $name = isset($_POST['name']) ? trim($_POST['name']) : '';
  37.
      $email = isset($_POST['email']) ? trim($_POST['email']) : '';
  38.
      $mesg = isset($_POST['mesg']) ? trim($_POST['mesg']) : '';
  39.
       
  40.
      if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) $errorEmail = true;
  41.
      if (strlen($name)<3) $errorName = true;
  42.
      if (strlen($mesg)<10) $errorMesg = true;
  43.
       
  44.
      // Display the form again as there was an error
  45.
      if ($errorName || $errorEmail || $errorMesg) {
  46.
      showForm($errorName,$errorEmail,$errorMesg);
  47.
      } else {
  48.
      echo 'Submission was success!';
  49.
      }
  50.
       
  51.
      }
  52.
      ?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.