Jump to content

do not diplay form upon submission


php_begins
 Share

Recommended Posts

hi i have the following contact us form which works fine. i need lil more tweaking.

Right now when i submit the form it displays the information "blah blah", "the form has been submitted successfully" and also the form.

What i want to do is if the form has been submitted successfully i need not display the form again.

I need to display the data before the form field:

"Blah Blah"(information before the form code)

"the form has been submitted successfully"

I do not need to display the form if it has been a successful submission.

here is my code:

 

<?php

include($headerpath);

//change this to use mysql count function

$totalentriesrow = mysql_query("SELECT DISTINCT userid FROM user", $con);
$totalentriesrow = mysql_num_rows($totalentriesrow);

?>
<title><?PHP echo $site_name; ?> Advertising</title>
<BR><BR>
<table cellpadding="5"  cellspacing="1" bgcolor="white" border="0" width="900" align="center" style='border-top: 1px; border-right: 1px; border-left: 1px; border-bottom: 1px; border-color: black; border-style: solid;'>
<tr>
<td bgcolor='<?PHP echo $head; ?>' align='left'><b><font color='<?PHP echo $head_font_color; ?>' size='2' face='verdana'><?PHP echo $site_name; ?> Advertising</font></b>
Blah Blah Blah Blah
</td>

</tr>

<?

//echo '<center><h4><font color="blue"><br>CONTACT US<br></font></h4></center>';

// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['submit']))
{

      // Each time theres an error, add an error message to the error array
      // using the field name as the key.
      if (empty($_POST['first_name']))
          $arrErrors['first_name'] = '<br><font color="red">Please provide your first name.</font>';
      if (empty($_POST['last_name']))
          $arrErrors['last_name'] = '<br><font color="red">Please provide your last name.</font>';
      if (empty($_POST['business_name']))
          $arrErrors['business_name'] = '<br><font color="red">Please provide your business name.</font>';
      if (empty($_POST['website_url']))
          $arrErrors['website_url'] = '<br><font color="red">Please provide a website url.</font>';
      if (empty($_POST['street_address']))
          $arrErrors['street_address'] = '<br><font color="red">Please provide your street address.</font>';
      if (empty($_POST['city']))
          $arrErrors['city'] = '<br><font color="red">Please provide your city name.</font>';
      if (empty($_POST['state']))
          $arrErrors['state'] = '<br><font color="red">Please provide your state.</font>';
      if (empty($_POST['zip']))
          $arrErrors['zip'] = '<br><font color="red">Please provide your zip.</font>';
      if (empty($_POST['country']))
          $arrErrors['country'] = '<br><font color="red">Please provide your country.</font>';
      if (empty($_POST['email_address']))
          $arrErrors['email_address'] = '<br><font color="red">A valid email address is required.</font>';
      if (empty($_POST['phone']) || (!is_numeric($_POST['phone'])))
          $arrErrors['phone'] = '<br><font color="red">Phone number cannot be empty and has to be numeric.</font>';
      if (empty($_POST['description']))
          $arrErrors['description'] = '<br><font color="red">Description cannot be empty.</font>';


      // If the error array is empty, there were no errors.
  // Insert form processing here.

      if (count($arrErrors) == 0)
      {


    $first_name=cleaninput($_POST['first_name']);
    $last_name=cleaninput($_POST['last_name']);
    $business_name=cleaninput($_POST['business_name']);
    $website_url=cleaninput($_POST['website_url']);
        $street_address=cleaninput($_POST['street_address']);
    $city=cleaninput($_POST['city']);
    $state=cleaninput($_POST['state']);
        $zip=cleaninput($_POST['zip']);
        $country=cleaninput($_POST['country']);
    $email_address=cleaninput($_POST['email_address']);
    $phone=cleaninput($_POST['phone']);
    $description=cleaninput($_POST['description']);

	    $to = $advertising_contacts;
        $subject = "Advertisement Contact";
        $message="You have a new advertising contact<br>";
        $message.="<b>First name:</b> ".stripslashes($first_name)."<br><b>Last Name:</b> ".stripslashes($last_name);
        $message.="<br><b>Business Name:</b> ".stripslashes($business_name)."<br><b>Business Description: </b>".stripslashes($description)."<br><b>Business URL:</b> ".stripslashes($website_url);
        $message.="<br><b>Street Address:</b> ".stripslashes($street_address)."<br><b>City:</b> ".stripslashes($city);
        $message.="<br><b>State:</b> ".stripslashes($state)."<br><b>Zip:</b> ".stripslashes($zip)."<br><b>Country:</b> ".stripslashes($country);
        $message.="<br><b>Email:</b> ".stripslashes($email_address)."<br><b>Phone:</b> ".stripslashes($phone);
        $from = "webmaster@example.com";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: Admin <Admin@groupbuilder.com>' . "\r\n";

	   // Send email
	   mail($to,$subject,$message,$headers);

       //escapeinput for inserting into database

	   $first_name=escapeinput($first_name);
	   $last_name=escapeinput($last_name);
	   $website_url=escapeinput($website_url);
	   $street_address=escapeinput($street_address);
	   $city=escapeinput($city);
	   $state=escapeinput($state);
	   $zip=escapeinput($zip);
	   $country=escapeinput($country);
	   $email=escapeinput($email);
	   $phone=escapeinput($phone);
	   $description=escapeinput($description);
	   $dateline=time();

       //Insert the details into database

	   $insert_contacts=mysql_query("INSERT INTO adcontacts(first_name,last_name,email_address,phone,business_name,description,website_url,street_address,city,state,zip,country,dateline) VALUES('$first_name','$last_name','$email_address','$phone','$business_name','$description','$website_url','$street_address','$city','$state','$zip','$country','$dateline')") or die(mysql_error());

       echo "<center>Form Submitted Successfully</center><br>";

      }
      else
      {

        // The error array had something in it. There was an error.
        // Start adding error text to an error string.
        echo "<center>There was an error in the form<br></center>";

    $strError="";
        foreach ($arrErrors as $error)
        {
           $strError .= $error;
        }

      }
}
?>



<tr>
   <td>

<?
     echo "<table align= 'center' width='50%' style='border-top: 1px; border-right: 1px; border-left: 1px; border-bottom: 1px; border-color: black; border-style: solid;'>";
?>
<tr>
  <td>
   <form action="<?php echo $PHP_SELF;?>" method="post">
      <tr height='40'>
         <td>
           <font color="black"><B> First Name: </B></font>
         </td>
 <td><input type="text" size ="40" name="first_name" value="<? if(!empty($strError)) {echo cleaninput($_POST['first_name']);}?>" />
            <?php if (!empty($arrErrors['first_name'])) echo $arrErrors['first_name']; ?>
 </td>

      </tr>
      <tr height='40'>
     <td><font color="black"><B> Last Name: </B></font></td>
     <td><input type="text" size ="40" name="last_name" value="<? if(!empty($strError)) { echo cleaninput($_POST['last_name']);}?>"/>
     <?php if (!empty($arrErrors['last_name'])) echo $arrErrors['last_name']; ?>
             </td>
      </tr>

      <tr height='40'>
     <td><font color="black"><B> Email Address: </B></font></td>
     <td><input type="text" size ="40" name="email_address" value="<? if(!empty($strError)) { echo cleaninput($_POST['email_address']);}?>"/>
     <?php if (!empty($arrErrors['email_address'])) echo $arrErrors['email_address']; ?>
             </td>
      </tr>
       <tr height='35'>
	     <td><font color="black"><B> Business Name: </B></font></td>
	     <td><input type="text" size ="40" name="business_name" value="<? if(!empty($strError)) { echo cleaninput($_POST['business_name']);}?>" />
      <?php if (!empty($arrErrors['business_name'])) echo $arrErrors['business_name']; ?>
             </td>
      </tr>

      <tr>
         <td><font color="black"><B> Business Description: </B></font></td>
         <td ><textarea rows=7 cols=31 name="description"><? if(!empty($strError)) { echo cleaninput($_POST['description']);}?></textarea>
         <?php if (!empty($arrErrors['description'])) echo $arrErrors['description']; ?>
         </td>
      </tr>
       <tr height='40'>
	     <td><font color="black"><B> Business URL: </B></font></td>
	     <td><input type="text" size ="40" name="website_url" value="<? if(!empty($strError)) { echo cleaninput($_POST['website_url']);}?>" />
        <?php if (!empty($arrErrors['website_url'])) echo $arrErrors['website_url']; ?>
             </td>
      </tr>
         <tr height='40'>
   	     <td><font color="black"><B> Business Phone: </B></font></td>
   	     <td><input type="text" size ="40" name="phone" value="<? if(!empty($strError)) { echo cleaninput($_POST['phone']);}?>"/>
	<?php if (!empty($arrErrors['phone'])) echo $arrErrors['phone']; ?>
             </td>
      </tr>
      <tr height='40'>
     <td><font color="black"><B> Street Address: </B></font></td>
     <td><input type="text" size ="40" name="street_address" value="<? if(!empty($strError)) { echo cleaninput($_POST['street_address']);}?>" />
	<?php if (!empty($arrErrors['street_address'])) echo $arrErrors['street_address']; ?>
             </td>
      </tr>
      <tr height='40'>
     <td><font color="black"><B> City: </B></font></td>
     <td><input type="text" size ="40" name="city" value="<? if(!empty($strError)) { echo cleaninput($_POST['city']);}?>" />
	<?php if (!empty($arrErrors['city'])) echo $arrErrors['city']; ?>
             </td>
      </tr>
       <tr height='40'>
     <td><font color="black"><B> State: </B></font></td>
     <td><input type="text" size ="40" name="state" value="<? if(!empty($strError)) { echo cleaninput($_POST['state']);}?>"/>
	<?php if (!empty($arrErrors['state'])) echo $arrErrors['state']; ?>
             </td>
      </tr>
        <tr height='40'>
	     <td><font color="black"><B> Zip: </B></font></td>
	     <td><input type="text" size ="40" name="zip" value="<? if(!empty($strError)) { echo cleaninput($_POST['zip']);}?>"/>
	<?php if (!empty($arrErrors['zip'])) echo $arrErrors['zip']; ?>
             </td>
      </tr>
      <tr height='40'>
     <td><font color="black"><B> Country: </B></font></td>
     <td>
     <select name="country">
     <option value="<? if(!empty($strError)) { echo $_POST['country'];}?>"><?echo cleaninput($_POST['country']);?></option>
     <?php foreach($array as $key=>$value){ ?>
     <option value="<?php echo $value; ?>"><?php echo $value; ?></option>

     <?php }?>
     </select>
	<?php if (!empty($arrErrors['country'])) echo $arrErrors['country']; ?>
     </td>
</tr>
      <tr height='35'>
         <td></td>
         <td><input type="submit" name="submit" value="submit" /></td>
      </tr>

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


 

Link to comment
Share on other sites

 

<?php


include($headerpath);


//change this to use mysql count function


$totalentriesrow = mysql_query("SELECT DISTINCT userid FROM user", $con);
$totalentriesrow = mysql_num_rows($totalentriesrow);


?>
<title><?PHP echo $site_name; ?> Advertising</title>
<BR><BR>
<table cellpadding="5"  cellspacing="1" bgcolor="white" border="0" width="900" align="center" style='border-top: 1px; border-right: 1px; border-left: 1px; border-bottom: 1px; border-color: black; border-style: solid;'>
   <tr>
   <td bgcolor='<?PHP echo $head; ?>' align='left'><b><font color='<?PHP echo $head_font_color; ?>' size='2' face='verdana'><?PHP echo $site_name; ?> Advertising</font></b>
   Blah Blah Blah Blah
   </td>
   
   </tr>


<?


//echo '<center><h4><font color="blue"><br>CONTACT US<br></font></h4></center>';


// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['submit']))
{


      // Each time theres an error, add an error message to the error array
      // using the field name as the key.
      if (empty($_POST['first_name']))
          $arrErrors['first_name'] = '<br><font color="red">Please provide your first name.</font>';
      if (empty($_POST['last_name']))
          $arrErrors['last_name'] = '<br><font color="red">Please provide your last name.</font>';
      if (empty($_POST['business_name']))
          $arrErrors['business_name'] = '<br><font color="red">Please provide your business name.</font>';
      if (empty($_POST['website_url']))
          $arrErrors['website_url'] = '<br><font color="red">Please provide a website url.</font>';
      if (empty($_POST['street_address']))
          $arrErrors['street_address'] = '<br><font color="red">Please provide your street address.</font>';
      if (empty($_POST['city']))
          $arrErrors['city'] = '<br><font color="red">Please provide your city name.</font>';
      if (empty($_POST['state']))
          $arrErrors['state'] = '<br><font color="red">Please provide your state.</font>';
      if (empty($_POST['zip']))
          $arrErrors['zip'] = '<br><font color="red">Please provide your zip.</font>';
      if (empty($_POST['country']))
          $arrErrors['country'] = '<br><font color="red">Please provide your country.</font>';
      if (empty($_POST['email_address']))
          $arrErrors['email_address'] = '<br><font color="red">A valid email address is required.</font>';
      if (empty($_POST['phone']) || (!is_numeric($_POST['phone'])))
          $arrErrors['phone'] = '<br><font color="red">Phone number cannot be empty and has to be numeric.</font>';
      if (empty($_POST['description']))
          $arrErrors['description'] = '<br><font color="red">Description cannot be empty.</font>';




      // If the error array is empty, there were no errors.
     // Insert form processing here.


      if (count($arrErrors) == 0)
      {




       $first_name=cleaninput($_POST['first_name']);
       $last_name=cleaninput($_POST['last_name']);
       $business_name=cleaninput($_POST['business_name']);
       $website_url=cleaninput($_POST['website_url']);
        $street_address=cleaninput($_POST['street_address']);
       $city=cleaninput($_POST['city']);
       $state=cleaninput($_POST['state']);
        $zip=cleaninput($_POST['zip']);
        $country=cleaninput($_POST['country']);
       $email_address=cleaninput($_POST['email_address']);
       $phone=cleaninput($_POST['phone']);
       $description=cleaninput($_POST['description']);


        $to = $advertising_contacts;
        $subject = "Advertisement Contact";
        $message="You have a new advertising contact<br>";
        $message.="<b>First name:</b> ".stripslashes($first_name)."<br><b>Last Name:</b> ".stripslashes($last_name);
        $message.="<br><b>Business Name:</b> ".stripslashes($business_name)."<br><b>Business Description: </b>".stripslashes($description)."<br><b>Business URL:</b> ".stripslashes($website_url);
        $message.="<br><b>Street Address:</b> ".stripslashes($street_address)."<br><b>City:</b> ".stripslashes($city);
        $message.="<br><b>State:</b> ".stripslashes($state)."<br><b>Zip:</b> ".stripslashes($zip)."<br><b>Country:</b> ".stripslashes($country);
        $message.="<br><b>Email:</b> ".stripslashes($email_address)."<br><b>Phone:</b> ".stripslashes($phone);
        $from = "webmaster@example.com";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: Admin <Admin@groupbuilder.com>' . "\r\n";


       // Send email
       mail($to,$subject,$message,$headers);


       //escapeinput for inserting into database


       $first_name=escapeinput($first_name);
       $last_name=escapeinput($last_name);
       $website_url=escapeinput($website_url);
       $street_address=escapeinput($street_address);
       $city=escapeinput($city);
       $state=escapeinput($state);
       $zip=escapeinput($zip);
       $country=escapeinput($country);
       $email=escapeinput($email);
       $phone=escapeinput($phone);
       $description=escapeinput($description);
       $dateline=time();


       //Insert the details into database


       $insert_contacts=mysql_query("INSERT INTO adcontacts(first_name,last_name,email_address,phone,business_name,description,website_url,street_address,city,state,zip,country,dateline) VALUES('$first_name','$last_name','$email_address','$phone','$business_name','$description','$website_url','$street_address','$city','$state','$zip','$country','$dateline')") or die(mysql_error());


       echo "<center>Form Submitted Successfully</center><br>";


      }
      else
      {


        // The error array had something in it. There was an error.
        // Start adding error text to an error string.
        echo "<center>There was an error in the form<br></center>";


       $strError="";
        foreach ($arrErrors as $error)
        {
           $strError .= $error;
        }


      }
   //} moved this
?>






<tr>
   <td>


<?
     echo "<table align= 'center' width='50%' style='border-top: 1px; border-right: 1px; border-left: 1px; border-bottom: 1px; border-color: black; border-style: solid;'>";
?>
<tr>
  <td>
   <form action="<?php echo $PHP_SELF;?>" method="post">
      <tr height='40'>
         <td>
           <font color="black"><B> First Name: </B></font>
         </td>
    <td><input type="text" size ="40" name="first_name" value="<? if(!empty($strError)) {echo cleaninput($_POST['first_name']);}?>" />
            <?php if (!empty($arrErrors['first_name'])) echo $arrErrors['first_name']; ?>
    </td>


      </tr>
      <tr height='40'>
        <td><font color="black"><B> Last Name: </B></font></td>
        <td><input type="text" size ="40" name="last_name" value="<? if(!empty($strError)) { echo cleaninput($_POST['last_name']);}?>"/>
        <?php if (!empty($arrErrors['last_name'])) echo $arrErrors['last_name']; ?>
             </td>
      </tr>


      <tr height='40'>
        <td><font color="black"><B> Email Address: </B></font></td>
        <td><input type="text" size ="40" name="email_address" value="<? if(!empty($strError)) { echo cleaninput($_POST['email_address']);}?>"/>
        <?php if (!empty($arrErrors['email_address'])) echo $arrErrors['email_address']; ?>
             </td>
      </tr>
       <tr height='35'>
         <td><font color="black"><B> Business Name: </B></font></td>
         <td><input type="text" size ="40" name="business_name" value="<? if(!empty($strError)) { echo cleaninput($_POST['business_name']);}?>" />
         <?php if (!empty($arrErrors['business_name'])) echo $arrErrors['business_name']; ?>
             </td>
      </tr>


      <tr>
         <td><font color="black"><B> Business Description: </B></font></td>
         <td ><textarea rows=7 cols=31 name="description"><? if(!empty($strError)) { echo cleaninput($_POST['description']);}?></textarea>
         <?php if (!empty($arrErrors['description'])) echo $arrErrors['description']; ?>
         </td>
      </tr>
       <tr height='40'>
         <td><font color="black"><B> Business URL: </B></font></td>
         <td><input type="text" size ="40" name="website_url" value="<? if(!empty($strError)) { echo cleaninput($_POST['website_url']);}?>" />
           <?php if (!empty($arrErrors['website_url'])) echo $arrErrors['website_url']; ?>
             </td>
      </tr>
         <tr height='40'>
           <td><font color="black"><B> Business Phone: </B></font></td>
           <td><input type="text" size ="40" name="phone" value="<? if(!empty($strError)) { echo cleaninput($_POST['phone']);}?>"/>
      <?php if (!empty($arrErrors['phone'])) echo $arrErrors['phone']; ?>
             </td>
      </tr>
      <tr height='40'>
        <td><font color="black"><B> Street Address: </B></font></td>
        <td><input type="text" size ="40" name="street_address" value="<? if(!empty($strError)) { echo cleaninput($_POST['street_address']);}?>" />
      <?php if (!empty($arrErrors['street_address'])) echo $arrErrors['street_address']; ?>
             </td>
      </tr>
      <tr height='40'>
        <td><font color="black"><B> City: </B></font></td>
        <td><input type="text" size ="40" name="city" value="<? if(!empty($strError)) { echo cleaninput($_POST['city']);}?>" />
      <?php if (!empty($arrErrors['city'])) echo $arrErrors['city']; ?>
             </td>
      </tr>
       <tr height='40'>
        <td><font color="black"><B> State: </B></font></td>
        <td><input type="text" size ="40" name="state" value="<? if(!empty($strError)) { echo cleaninput($_POST['state']);}?>"/>
      <?php if (!empty($arrErrors['state'])) echo $arrErrors['state']; ?>
             </td>
      </tr>
        <tr height='40'>
         <td><font color="black"><B> Zip: </B></font></td>
         <td><input type="text" size ="40" name="zip" value="<? if(!empty($strError)) { echo cleaninput($_POST['zip']);}?>"/>
      <?php if (!empty($arrErrors['zip'])) echo $arrErrors['zip']; ?>
             </td>
      </tr>
      <tr height='40'>
        <td><font color="black"><B> Country: </B></font></td>
        <td>
        <select name="country">
        <option value="<? if(!empty($strError)) { echo $_POST['country'];}?>"><?echo cleaninput($_POST['country']);?></option>
        <?php foreach($array as $key=>$value){ ?>
        <option value="<?php echo $value; ?>"><?php echo $value; ?></option>


        <?php }?>
        </select>
      <?php if (!empty($arrErrors['country'])) echo $arrErrors['country']; ?>
        </td>
</tr>
      <tr height='35'>
         <td></td>
         <td><input type="submit" name="submit" value="submit" /></td>
      </tr>


   </form>
   </tr>
   </td>
   </table>
   </td>
   </tr>
<?php } /* TO HERE */ ?>
</table>




Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.