Jump to content

online contact form error


regoch

Recommended Posts

Hello!

I got this script for online contact form. When i got all field filled it's send mail and show page normally.  but when i don't fill all fields it's show what field it's not filled but not continue with rest of site, don't show right column (podaci_desno) or footer (dno_unutra). I try remove die(); after errors but no help from that. Any ideas?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Plivački klub Zadar</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Fer Projekt, Put Murvice 14, Zadar, 099/212-9600" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/css/pk-zadar.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/css/fontovi.css" type="text/css" charset="utf-8" />
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/banners.min.js"></script>
<script type="text/javascript" src="/js/jQueryEqualHeight.js"></script>
</head>

<body>
<div id="pozadina_unutra">
<div id="sadrzaj_unutra">
<div id="meni_unutra">
<table id="Table_01" style="width:991px;height:138px;" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td rowspan="2">
		<img src="/images/menu_unutra_01.png" width="1" height="138" alt="PK Zadar" /></td>
	<td rowspan="2">
		<a href="/">
			<img src="/images/menu_unutra_02.png" width="310" height="138" border="0" alt="PK Zadar" /></a></td>
	<td rowspan="2">
		<img src="/images/menu_unutra_03.png" width="77" height="138" alt="PK Zadar" /></td>
	<td>
		<a href="/">
			<img src="/images/menu_unutra_04.png" onmouseover="this.src='/images/menu_unutra_04a.png'" onmouseout="this.src='/images/menu_unutra_04.png'" width="90" height="99" border="0" alt="PK Zadar" /></a></td>
	<td>
		<a href="/o-klubu">
			<img src="/images/menu_unutra_05.png" onmouseover="this.src='/images/menu_unutra_05a.png'" onmouseout="this.src='/images/menu_unutra_05.png'" width="83" height="99" border="0" alt="PK Zadar" /></a></td>
	<td>
		<a href="/natjecanja">
			<img src="/images/menu_unutra_06.png" onmouseover="this.src='/images/menu_unutra_06a.png'" onmouseout="this.src='/images/menu_unutra_06.png'" width="98" height="99" border="0" alt="PK Zadar" /></a></td>
	<td>
		<a href="/novost">
			<img src="/images/menu_unutra_07.png" onmouseover="this.src='/images/menu_unutra_07a.png'" onmouseout="this.src='/images/menu_unutra_07.png'" width="85" height="99" border="0" alt="PK Zadar" /></a></td>
	<td>
		<a href="/galerije">
			<img src="/images/menu_unutra_08.png" onmouseover="this.src='/images/menu_unutra_08a.png'" onmouseout="this.src='/images/menu_unutra_08.png'" width="81" height="99" border="0" alt="PK Zadar" /></a></td>
	<td>
		<a href="/treneri">
			<img src="/images/menu_unutra_09.png" onmouseover="this.src='/images/menu_unutra_09a.png'" onmouseout="this.src='/images/menu_unutra_09.png'" width="74" height="99" border="0" alt="PK Zadar" /></a></td>
	<td>
		<a href="/kontakt">
			<img src="/images/menu_unutra_10a.png" onmouseover="this.src='/images/menu_unutra_10a.png'" onmouseout="this.src='/images/menu_unutra_10a.png'" width="92" height="99" border="0" alt="PK Zadar" /></a></td>
</tr>
<tr>
	<td colspan="7">
		<img src="/images/menu_unutra_11.png" width="603" height="39" alt="PK Zadar" /></td>
</tr>
</table>
</div><!-- Kraj menu index -->
<div id="podaci_livo">
<span class="naslov">Kontakt</span><br /><br />
Adresa:<br /> 	
Plivački klub ZADAR<br />
Kolovare bb<br />
23000 ZADAR<br /><br />  	 
Telefon: <br />	+385 (23) 312-320<br /><br />
E-mail adrese: <br />
info@pkzadar.hr<br />
uprava@pkzadar.hr<br />
tajnik@pkzadar.hr<br />
treneri@pkzadar.hr<br /><br />
Radno vrijeme u kojem nas možete kontaktirati osobno ili telefonom je:<br />
Radnim danom:<br /> 	
od 8,00 - 11,00 sati i
od 17,00 - 19,00 sati
<br /> 	 
Subotom:<br />
od 9,00 - 11,00 sati
<br /><br />
<?php
if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "luka@fer-projekt.com";
    $email_subject = "Your email subject line";
     
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }
     
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>
<form name="contactform" method="post" action="">
<table width="450px">
</tr>
<tr>
<td valign="top">
  <label for="first_name">First Name *</label>
</td>
<td valign="top">
  <input  type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>

<tr>
<td valign="top"">
  <label for="last_name">Last Name *</label>
</td>
<td valign="top">
  <input  type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
  <label for="email">Email Address *</label>
</td>
<td valign="top">
  <input  type="text" name="email" maxlength="80" size="30">
</td>

</tr>
<tr>
<td valign="top">
  <label for="telephone">Telephone Number</label>
</td>
<td valign="top">
  <input  type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
  <label for="comments">Comments *</label>
</td>
<td valign="top">
  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>

</tr>
<tr>
<td colspan="2" style="text-align:center">
  <input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
<br /><br />
</div><!-- Kraj podaci_livo -->
<div id="podaci_desno"> 
<?php include("include/desno_box.php")?>
</div><!-- Kraj podaci_desno -->
<div class="clear" />
</div><!-- Kraj sadrzaj_unutra -->
</div><!-- Kraj pozadina_unutra -->
<div id="dno_unutra">
<?php include("include/dno_box.php")?>
</div><!-- Kraj dno_unutra -->
</body>
</html>

Link to comment
Share on other sites

you should separate the functions from the code, and it's the die(); function being called in your 'died()' function which is stopping the rest of the page from showing... try somethign like this

<?php
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "luka@fer-projekt.com";
    $email_subject = "Your email subject line";
     

     
$error = false;

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        $error_message = 'We are sorry, but there appears to be a problem with the form you submitted.';  
$error=true;
    } 

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
     
    $error_message = (isset($error_message))?$error_message:'';
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
$error=true;
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
$error=true;
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
$error=true;
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
$error=true;
  }

#check that errors weren't set
  if($error) {

    $email_message = "Form details below.\n\n";
     
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 

echo 'Thank you for contacting us. We will be in touch with you very soon.';

}


  }

Link to comment
Share on other sites

the whole point of the form is that users fill them in and go to the next page...

but if you want to proceed to proceed anyway (kinda pointless) you can do away the funtion died()

function died($error) {        
// your error code can go here        
echo "We are very sorry, but there were error(s) found with the form you submitted. ";        
echo "These errors appear below.<br /><br />";        
echo $error."<br /><br />";        
echo "Please go back and fix these errors.<br /><br />";        
die();    
}

and the validation

if(!isset($_POST['first_name']) ||        
!isset($_POST['last_name']) ||        
!isset($_POST['email']) ||        
!isset($_POST['telephone']) ||        
!isset($_POST['comments'])) {        
died('We are sorry, but there appears to be a problem with the form you submitted.');          
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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