Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-03-2012, 03:37 PM   PM User | #1
vuvuadi
New to the CF scene

 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vuvuadi is an unknown quantity at this point
Exclamation Form submitting in Chrome but not the other browsers

Hi.
I'm having a problem submitting a form with this code:

PHP

Code:
<?php session_start() ?>
<?php
$to = 'you@example.com';
$subject = 'Subject';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Me' . "\r\n";
$response = null;
define('EMAIL_PATTERN', '/^[\w\.-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]+$/');
define('EMAIL_LENGTH', 200);



if (isset($_POST['submit'])) {
	
	// check all required fields
	if (!empty($_POST['firstname']) &&
		!empty($_POST['email']) &&
		!empty($_POST['contact']) &&
		!empty($_POST['organization']) && 
		!empty($_POST['website'])){
		
		// escape all inputs
		$firstname = escape($_POST['firstname']);
		$email = escape($_POST['email']);
		$contact = escape($_POST['contact']);
		$organization = escape($_POST['organization']);
		$website = escape($_POST['website']);
				
		// sanitize the prospect e-mail address
		if (sanitize($email, EMAIL_PATTERN, EMAIL_LENGTH)) {
			// send mail to prospect and clayant
			$sentmail = mail($to, $subject, 'Name: ' . $firstname . "\n\n" . "Email: " . $email . "\n\n" . "Contact Number: " . $contact . "\n\n" . "Organization: " . $organization . "\n\n" . "Website: " . $website, $headers);

				header('location: thanks.php');

		} else {
			// bail
			$response = 'Please check your e-mail address again.';
		}
		
	} else {
		// bail
		$response = 'Please enter all required fields marked with an asterisk (*).';
	}
}


function escape($string) {
	return (!empty($string)) ? strip_tags(trim($string)) : null;
}

function sanitize($string, $pattern, $length) {
	if (strlen($string) <= $length) {
		if (preg_match($pattern, $string)) {
			return true;
		}
	}
	return false;
}

function get_post($value) {
	echo (@!empty($_POST[$value])) ? trim($_POST[$value]) : null;
}

?>

and HTML
Code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="form" name="form" >
				<?php
						if (!empty($response)) {
							echo '<p class="error">' . $response . '</p>' . "\n";
							}
				?>
				<label for="firstname">Your first name *</label>
				<input type="text" name="firstname" id="firstname" value="<?php get_post('firstname'); ?>" />
				<label for="email">Your Email Address *</label>
				<input type="text" name="email" id="email" value="<?php get_post('email'); ?>" />
				<label for="contact">Contact number *</label>
				<input type="text" name="contact" id="contact" value="<?php get_post('contact'); ?>" />
				<label for="organization">Organization *</label>
				<input type="text" name="organization" id="organization" value="<?php get_post('organization'); ?>" />
				<label for="website">Website *</label>
				<input type="text" name="website" id="website" value="<?php get_post('website'); ?>" />
				<input type="image" name="submit" id="submit" alt="submit" src="images/submit-btn.png" width="280" height="60" class="submit-btn" />
			</form>
It just refreshes the page in FF and IE but redirects to the thank you page and sends me an email in chrome
vuvuadi is offline   Reply With Quote
Old 05-03-2012, 04:34 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
Well, for one thing don't name the form "form", or the class. form is a reserved word. Name the form "emailForm" or something.
WolfShade is offline   Reply With Quote
Old 05-03-2012, 04:35 PM   PM User | #3
jmj001
Regular Coder

 
Join Date: Jan 2012
Posts: 271
Thanks: 2
Thanked 65 Times in 65 Posts
jmj001 is an unknown quantity at this point
You probably need an actual submit button... not just an image of one..

try just putting in a standard old submit button and see if that works

change
PHP Code:
<input type="image" name="submit" id="submit" alt="submit" src="images/submit-btn.png" width="280" height="60" class="submit-btn"  /> 
to
PHP Code:
<input type="submit" name="submit" id="submit" alt="submit" src="images/submit-btn.png" width="280" height="60" class="submit-btn"  /> 

Last edited by jmj001; 05-03-2012 at 04:37 PM..
jmj001 is offline   Reply With Quote
Old 05-03-2012, 05:29 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by vuvuadi View Post
if (isset($_POST['submit'])) {
I really cannot stress enough how much of a bad idea that is. Please see my signature, the link and the video for details why.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Old 05-03-2012, 06:16 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
^
Not to mention that image submits do not contain just the name. They contain the name_x and name_y attributes. Check the fields in use instead, this way you don't need to concern yourself with if it was submitted from an image input or a submit input.
Lets see if I can find this in the docs. Yeah, check this link for more information: http://ca3.php.net/manual/en/faq.htm...tml.form-image
The actual explanation is now incorrect. Since register globals are gone as of 5.4, there is no reason that $_GET/$_POST['submit.x'] will not work. This is a limitation of the possible use of register globals, but I somehow doubt that the functionality will be reverted.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
form, html, php, submit

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:45 AM.


Advertisement
Log in to turn off these ads.