Apostrophe Error In Contact Form

I’m using a pre-made contact form I found online. It generates an “Invalid characters” error whenever sending a message containing “that’s” instead of “thats”, “can’t” instead of cant, etc.

How can I remedy this?

…Thanks:

[php]

<?php #This line must remain here. Thankyou. 'Hacker Fighter' PHP contact form V 1.1. Copyright 2011 Joshua Luther Hunt-Smith, all rights reserved. Project page URL: servertosite.com/php-contact-forms-open-source hacker-fighter.html This project is released under the BSD license: creativecommons.org/licenses/BSD/ function mailio($chk){ if(preg_match('/^[\w.-]+@[\w.-]+\.([\w.]{2,10})\z/',$chk) && strlen($chk) < 70) {;}else if($chk===''){die('

Email address input left empty. Please go back and put in your email address (!)

');}else{die('

Invalid email address entered. Please go back and fix it before sending (!)

');}} function texti($zn){ if(!preg_match('/^([\w-\s]+)\z/',$zn) && strlen($chk) < 70){die('

Invalid characters entered in a text/number field or else text exceeds 70 character limit (Note: The main message text area has a much larger 20000 character limit). Please go back and fix before sending (!)

');}} function txar($xa){ if(!preg_match('/^([\w$&!?.,-\s\:\/]+)\z/',$xa)){die('

Invalid characters ( # @ ^ &#39; " \ * = ; % < > ` ~ + ) entered in text area (for example if you wrote the word that&#39;s take out the &#39;). Please go back and fix, Then click send (!)

');}} $subject= $_SERVER['HTTP_HOST']; $sbot= $_POST['text']; $name= $_POST['name']; $email= $_POST['email']; $deps= $_POST['whd']; $msg= $_POST['message']; //The list of email addresses shown below need to be changed to your receiving email addresses, please only change between the two ' ' in each instance. if you want more or less email addresses, copy or remove the whole line that says case 3 and either paste it below case 3, but rename it as case 4, you can repeat this for as many as you want, or to remove just leave it out the line you removed. Just remember that your corrsponding inputs in the contact interface will need to match and have more options and numerically numbered values added or deleted. switch($deps){ case 1:$you='[email protected]';break; case 2:$you='[email protected]';break; case 3:$you='[email protected]';break; default:die('

Hacking Attempted or a Processing Error Occured

');} if($sbot===''){$sbot;}else{die('

You filled in an input, that was supposed to remain blank as an anti spam measure. Go back and fill in only labeled inputs (!)

');} if(strlen($msg) > 20000){die('

20000 character text limit exceeded in message field, please go back and shorten message (!)

');} mailio($email); if($name===''){die('

You left the name field empty. Please go back and check that all fields are filled out, then send (!)

');}else{texti($name);} if($msg===''){die('

You didn\'t fill in a message. Please go back and check that all fields are filled out, then send (!)

');}else{txar($msg);} $br= nl2br($msg); $mx=<<<cb

Name:

$name

Email:

$email

Message:

$br cb; $hdrs = "From:$email\r\n"; $hdrs .= 'Content-type: text/html; charset=utf-8' . "\r\n"; mail($you,$subject,$mx,$hdrs); echo '

Thankyou. Your message has been sent

'; ?>

[/php]

Sounds like you just need to add the quote into your regex. For example:

Change this:

[php]’/^([\w$&!?.,-\s:/]+)\z/’[/php]

To this:

[php]’/^([\w$&!?.,-\s:/’]+)\z/’[/php]

You will notice the additional ’ at the end

Thanks for your suggestion… unfortunately I couldn’t get it to work. I replaced the code in the line below as directed but I still get the same error. :frowning:

Am I missing something?

if(!preg_match('/^([\w$&!?.,-\s\:\/\']+)\z/',$xa)){die('<h1>Invalid characters ( # @ ^ &#38;#38;#39; &quot; \ * = ; % &lt; &gt; ` ~ + ) entered in text area (for example if you wrote the word that&#38;#38;#39;s take out the &#38;#38;#39;). Please go back and fix, Then click send <span>(!)</span></h1>');}}

You have two different errors that both say “Invalid characters” - which one are you getting?

Sorry, I should have been more specific. An “invalid” entry in the message field results in:

“Invalid characters ( # @ ^ ’ " \ * = ; % < > ` ~ + ) entered in text area
(for example if you wrote the word that’s take out the '). Please go back and fix, Then click send!”

Works fine for me. You must have a different character causing the problem.

[php]
function txar($xa) {
if (!preg_match(’/^([\w$&!?.,-\s:/’]+)\z/’,$xa)) {
die(‘

Invalid characters ( # @ ^ &#38;#39; " \ * = ; % < > ` ~ + ) entered in text area (for example if you wrote the word that&#38;#39;s take out the &#38;#39;). Please go back and fix, Then click send (!)

’);
}
}
txar(“test’in…”); // no error
[/php]

Entering only the word “that’s” in the message box produces the error. Entering only the word “thats” does not.

Months later and I am STILL struggling with this issue. Please …can anyone help?

Thank You

I’m sorry unless I can duplicate your problem I can’t help.

Belated follow up…

I eventually gave up on trying to get this buggy form code to work properly. I ended up using “Fast Secure Contact Form” which works very well. I hope this helps someone else… :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service