Solved

Thickbox issue using PHP Form

Posted on 2008-10-10
4
1,581 Views
Last Modified: 2012-05-05
Hey all,

I'm  having a weird thickbox issue. I'm loading a simple PHP Mail Form into a thickbox window (which works fine) but, the form doesn't work on the initial load. To get it to work you need to hit the submit button. Once you hit the submit button it reloads and works fine. It's def not the form because if I go straight to the same form without the thickbox it works fine on the first try.

See it in action:
http://niceinstrumentation.com/contact-us.php
NORTH AMERICA uses thickbox, the other don't.

I didn't write the php code.

Below is the thickbox call
<a href="/mail/contact-mod-us.php?KeepThis=true&TB_iframe=true&width=450&height=260" class="thickbox">
<?
########################################################
# PHP Mail Function with Validation for email and phone#
########################################################
 
############ READ THIS FIRST ##############################
 
/*
   In order to get this form integrated and working you'll need to insert
   the right information in the right place. Wherever you see a # INSERT HERE #
   is where you'll make changes in order to customize the form for your client.
   
   It's easy, just look throught the code for: # INSERT HERE # and everything
   should work nicely.
 
   You don't have to worry about creating variables as this form loops through
   all controls you add to the page and adds their key and value pairs to the 
   generated email. YES! It's that simple.
 
   If you need more validation options ask for help or use dreamweaver behaviors.
*/
 
###########################################################
 
 
if ($_REQUEST['posted'] && isReferrerMatch()) {
	
 
	# validate correct email address
	if (!preg_match('/[a-z0-9\.\_\-]+\@[a-z0-9\_\-]+(.[a-z0-9\.\_\-]+)+/', $_POST['email'])) {
		$msg .= "<strong>EMAIL</strong> must be a valid email address.<br>";
	}
 
	if ($msg=='') {
	
		$DontSendKeys = array('posted','Submit','x','y');
		
		foreach ($_POST as $key=>$value) {
			if (!in_array($key,$DontSendKeys)) {
				$message .= strtoupper(str_replace('_',' ',$key)).": $value<br>";
			}
		}
		
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$headers .= 'From: sales@niceinstrumentation.com' . "\r\n";
		
		# INSERT HERE OPTIONAL #########################
		
		// if you want a bbc send to your email address for testing, uncomment 
		// the next line by deleting the "//" and put in your email address.		 
		
		$headers .= 'Bcc: rurth24@yahoo.com' ."\r\n"; 
		
		################################################
		
		
		# INSERT HERE ##################################
		
		/* 
		   you must uncomment the following two lines and change the value in
		   the $to and $subject variables in order for the form to work
		*/  
		 $subject = "Nice Instrumentation US Contact Form";
		 $to = "sales@niceinstrumentation.com";
 
		################################################
		
		send_mail($to,$subject,$message,$headers);
		$msg = "Your contact information has been sent.  Please allow 24-48 hours for a response.";
		
		# INSERT HERE ##################################
		
		/* 
		   you must uncomment the following lines and change the location
		   of where you would like the page to redirect after successful 
		   form submission.
		*/  
 
		 header("Location: thank-you.php");
		exit;
		################################################
		
	}
}
 
# send mail function
function send_mail($to,$subject,$message,$headers)
{
 
	mail($to,$subject,$message,$headers);
}
 
# check if form is posting to itself
function isReferrerMatch()
{
 
	if ($_SERVER['SERVER_PORT'] == 443) 
	{
		$http_protocol='https';
	} else {
		$http_protocol='http';
	}
	
	if ($_SERVER['HTTP_REFERER'] == $http_protocol.'://'.$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'])
	{
		return true;
	} else {
		return false;
	}
	
}
?>

Open in new window

0
Comment
Question by:rurth24
  • 3
4 Comments
 
LVL 9

Expert Comment

by:khaledf
ID: 22690624
the following line assumes you have $_REQUEST['posted'] set. this is not true unless you click the submit button

if ($_REQUEST['posted'] && isReferrerMatch()) {
0
 
LVL 9

Expert Comment

by:khaledf
ID: 22690691
sorry, misread the question.
0
 
LVL 9

Accepted Solution

by:
khaledf earned 500 total points
ID: 22690723
change this line
if ($_REQUEST['posted'] && isReferrerMatch()) {

to

if ($_REQUEST['posted']) {
0
 

Author Comment

by:rurth24
ID: 22692112
Thanks Khaledf.... that worked. AWESOME...
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question