?
Solved

Thickbox issue using PHP Form

Posted on 2008-10-10
4
Medium Priority
?
1,592 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

650 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