Jump to content

Recommended Posts

Hi

 

I have a simple form that uses an image for the submit button

 

<input type="image" src="images/contactSendBtn.jpg" alt="Submit Form" name="submit" value="submit" />

 

This submit button works in all browsers but not in IE. I've read that its something to do with IE not sending the submit variable correctly and instead sending submit_x.

 

Could anyone look at my script and tell me how I need to change this to get it to work with this input type of image.

 

Thanks

 

My script

 

<?php
$after = "/contact-success.php"; 
$oops = "/contact-failed.php";

if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] != "POST") {
    exit("<p>You did not press the submit button; this page should not be accessed directly.</p>");
} else {
    $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i";
    $profanity = "/(beastial|bestial|blowjob|clit|cock|cum|cunilingus|cunillingus|cunnilingus|cunt|ejaculate|fag|felatio|fellatio|fuk|fuks|fuck|fuck off|gangbang|gangbanged|gangbangs|hotsex|jism|jiz|kock|kondum|kum|kunilingus|orgasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|porn|pussies|pussy|spunk|xxx)/i";
    $spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazolam|ambien|ambian|amoxicillin|antivert|blackjack|backgammon|texas|holdem|poker|carisoprodol|ciara|ciprofloxacin|debt|dating|porn)/i";
    $bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i";

    if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) {
        exit("<p>Known spam bots are not allowed.</p>");
    }
    foreach ($_POST as $key => $value) {
        $value = trim($value);

        if (empty($value)) {
        	if (($key != "company" && $key != "telNo"))  
        		{
            exit("<p>Please go back and complete the required fields.</p>");      
            	}
        } elseif (preg_match($exploits, $value)) {
            exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>");
        } elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) {
            exit("<p>Please keep things clean, no naughty words!</p>");
        }

        $_POST[$key] = stripslashes(strip_tags($value));
    }

    if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) {
        exit("<p>How can we reply if you don't provide us with a valid email address?</p>");
    }

    $recipient = "steve@choicecleaningservices.co.uk";
    $subject = "Web Site Enquiry";
    
$message .= "Name: {$_POST['name']} \n";
$message .= "Company: {$_POST['company']} \n";
$message .= "Email: {$_POST['email']} \n";
$message .= "Tel: {$_POST['telNo']} \n";
$message .= "Message: {$_POST['message']} \n";


    $headers .= "From: {$_POST['email']}";

    if (mail($recipient,$subject,$message,$headers)) {
        echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">"; 
    } else {
        echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">";
    }
}
?>

i know a work around, but the way to find out if its submit_x would be print_r($_POST) to find out what that submit comes up with, i'm pretty sure that is what happens thoough with image submits, i had this issue myself in the past.

workaround: hidden field, check for hidden field in $_POST, go from there.

Not this again.

 

The only thing the w3.org specification states is  that the x and y coordinate where the image was clicked be sent to the server. AFAIK, all browsers do this. The browsers that send the name/value pair are doing their own thing outside of the w3.org specification.

 

You can use one of the following methods to detect if a form using an image as a submit button has been submitted -

 

1) Test if $_SERVER['REQUEST_METHOD'] == "POST"

 

2) Put a get parameter with a specific name/value on the end of the URL in the action="..." attribute and test for the get variable in your code.

 

3) Put a hidden field in the form with a specific name/value and test for it in your code.

 

4) Test for either the name_x or name_y coordinate from the image - http://us3.php.net/manual/en/faq.html.php#faq.html.form-image

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.