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
Solved

Thickbox issue using PHP Form

Posted on 2008-10-10
4
1,582 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
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 …

839 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