Solved

Thickbox issue using PHP Form

Posted on 2008-10-10
4
1,579 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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now