mallen Posted June 15, 2009 Share Posted June 15, 2009 <?php ob_start(); //required for html headers error //require_once('Connections/images.php'); include('includes/corefuncs.php'); // process the email if (array_key_exists('send', $_POST)) { $to = 'me@you.com'; // $subject = ' request'; // list expected fields $expected = array('name','email','company','comments'); // set required fields $required = array('name','email','comments'); // create empty array for any missing fields $missing = array(); // assume that there is nothing suspect $suspect = false; // create a pattern to locate suspect phrases $pattern = '/Content-Type:|Bcc:|Cc:/i'; // function to check for suspect phrases function isSuspect($val, $pattern, &$suspect) { // if the variable is an array, loop through each element // and pass it recursively back to the same function if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } } // check the $_POST array and any sub-arrays for suspect content isSuspect($_POST, $pattern, $suspect); if ($suspect) { $mailSent = false; unset($missing); } else { // process the $_POST variables foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } // otherwise, assign to a variable of the same name as $key elseif (in_array($key, $expected)) { ${$key} = $temp; } } } // validate the email address if (!empty($email)) { // regex to ensure no illegal characters in email address $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/'; // reject the email address if it doesn't match if (!preg_match($checkEmail, $email)) { array_push($missing, 'email'); } } // go ahead only if not suspect and all required fields OK if (!$suspect && empty($missing)) { // set default values for variables that might not exist // build the message $message = "Name: $name\n\n"; $message .= "Company: $company\n\n"; $message .= "Email: $email\n\n"; $message .= "Comments: $comments\n\n"; // limit line length to 70 characters $message = wordwrap($message, 70); // create additional headers $additionalHeaders = 'From: me'; if (!empty($email)) { $additionalHeaders .= "\r\nReply-To: $email"; } // send it $mailSent = mail($to, $subject, $message, $additionalHeaders); if ($mailSent) { // $missing is no longer needed if the email is sent, so unset it unset($missing); } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body id="contact"> <div id="wrapper"> <div id="topRight"> <div id="error"><?php if (isset($missing)) { echo '<p>The following are required:</p>'; echo '<ul>'; foreach($missing as $item) { echo "<li>$item</li>"; } echo '</ul>'; } elseif ($_POST && $mailSent) { echo '<p><strong>Your message has been sent. Thank you for your feedback.</strong></p>'; } ?> </div> <form name="cssform" action="contact.php" method="post" > <ul> <li> <label for="name">Name: </label> <input name="name" type="text" class="newfield" id="name" size="35" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['name']).'"';} ?>/> </li> <li> <label for="email">Email: </label> <input name="email" type="text" class="newfield" id="email" size="35"<?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['email']).'"';} ?> /> </li> <li> <label for="company">Company: </label> <input type="text" name="company" class="newfield" id="company" size="35" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['company']).'"';} ?>/> </li> <li> <label for="comments">Comments: </label> <textarea name="comments" id="comments" cols="1" rows="4"<?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['comments']).'"';} ?> ></textarea> </li> </ul> <input name="send" type="image" value="send" class="submitbutton" src="images/newbutton.jpg" /> </form> </div> </div> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 15, 2009 Share Posted June 15, 2009 http://us.php.net/manual/en/faq.html.php#faq.html.form-image That's because to use an image as a submit button, you must following the HTML specification. The button is only required to send the x,y coordinates where the image was clicked. You might want to just use a hidden field with a name and a value that you can test to see if the form has been submitted. Quote Link to comment Share on other sites More sharing options...
mallen Posted June 16, 2009 Author Share Posted June 16, 2009 <input name="send" type="image" value="send" class="submitbutton" src="images/newbutton.jpg" /> and I changed it to: <input name="send" type="submit" id="send" value="send" /> and it works in IE. So just "type" is causing the issue. So in this case Firefox is not following the HTML specification? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 16, 2009 Share Posted June 16, 2009 FF is doing its' own thing by sending the value="..." attribute, in addition to the x,y coordinates that the specification requires. Quote Link to comment Share on other sites More sharing options...
mallen Posted June 16, 2009 Author Share Posted June 16, 2009 Thanks for the reply. This is really interesting to know. So to send a value I would use a hidden value and put it in here? ..... if (array_key_exists('send', $_POST)) { ..... Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted June 16, 2009 Share Posted June 16, 2009 OR you can use <button>. Quote Link to comment Share on other sites More sharing options...
haku Posted June 16, 2009 Share Posted June 16, 2009 or you can check for send_x or send_y Quote Link to comment Share on other sites More sharing options...
mallen Posted June 16, 2009 Author Share Posted June 16, 2009 How would I use <button> How would this be written.? Quote Link to comment Share on other sites More sharing options...
haku Posted June 16, 2009 Share Posted June 16, 2009 http://particletree.com/features/rediscovering-the-button-element/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.