Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  2. #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Well, for one thing don't name the form "form", or the class. form is a reserved word. Name the form "emailForm" or something.

  3. #3
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    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.

  4. #4
    Master Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    5,119
    Thanks
    110
    Thanked 602 Times in 589 Posts
    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.
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.

  5. #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    17,025
    Thanks
    4
    Thanked 2,668 Times in 2,637 Posts
    ^
    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.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •