Free Web Hosting Forum
(#11 (permalink))
Old
Junior Member
tittbit is on a distinguished road
 
Posts: 12
Join Date: Feb 2012
Default 02-26-2012, 05:46 PM

the code u gave is a very useful but simple. u can use a html contact from with capctha,
following is the code if u want to use

The contact form with CAPTCHA

Here is the HTML code for the contact form:

<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label for="name">Name: </label>
<input type="text" name="name"
value="<?php echo htmlentities($name) ?>">
<label for="email">Email: </label>
<input type="text" name="email"
value="<?php echo htmlentities($visitor_email) ?>">
<label for="message">Message:</label>
<textarea name="message" rows=8 cols=30
><?php echo htmlentities($user_message) ?></textarea>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>"
id="captchaimg" >
<label for="message">Enter the code above here :</label>
<input id="6_letters_code" name="6_letters_code" type="text">
<input type="submit" value="Submit" name="submit">
</form>
The HTML form above contains the fields for name, email and message. In addition, we have the CAPTCHA image. The <img> tag for the CAPTCHA image points to the script captcha_code_file.php. The PHP script in 'captcha_code_file.php' creates the image for the captcha and saves the code in a session variable named '6_letters_code'.

Validating the CAPTCHA

When the form is submitted, we compare the value in the session variable(6_letters_code) with the submitted CAPTCHA code( the value in the text field 6_letters_code). If the codes match, then we proceed with emailing the form submission. Else we display an error.

Here is the code that does the server side processing:

if(isset($_POST['submit']))
{
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
if(empty($errors))
{
//send the email
$to = $your_email;
$subject="New form submission";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "A user $name submitted the contact form:\n".
"Name: $name\n".
"Email: $visitor_email \n".
"Message: \n ".
"$user_message\n".
"IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body,$headers);
header('Location: thank-you.html');
}
}
Customizing the CAPTCHA

The CAPTCHA script in the sample code download can be customized. If you open the script, you can see the first few lines of the code as shown below:

$image_width = 120;
$image_height = 40;
$characters_on_image = 6;
$font = './monofont.ttf';
//The characters that can be used in the CAPTCHA code.
//avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$random_dots = 0;
$random_lines = 20;
$captcha_text_color="0x142864";
$captcha_noise_color = "0x142864";
You can change the size of the CAPTCHA by changing $image_width & $image_height. The number of characters in the CAPTCHA can be changed by updating $characters_on_image. Similarly, the text color of the CAPTCHA can be customized by updating $captcha_text_color. The code adds some 'noise' in the image by adding random lines and dots. you can increase or decrease the noise. Please note that increasing the noise may make it difficult for your genuine visitors to read the code.
Reply With Quote
Sponsored Links
(#12 (permalink))
Old
Member
fididdly is on a distinguished road
 
Posts: 57
Join Date: Nov 2009
Default 02-27-2012, 03:40 AM

THANK you! This will be a huge help.
Reply With Quote
(#13 (permalink))
Old
Junior Member
tomyam is on a distinguished road
 
Posts: 4
Join Date: May 2012
Default it didn't work for me - 05-10-2012, 06:52 AM

Hi, I'm new with php.
I tried copy&paste the html and php files ,which was posted by RibbitHost on 7/3/2011, on to my website and uploaded both, but it didn't work for me. When I input contact form and click send, I get error and connect to 000webhost site.
In order for form to work, i need to upload the html form file and the php files, right?

I've been trying to figure out php form for days. Can any body help me?

Last edited by tomyam; 05-10-2012 at 06:57 AM. Reason: it was not clear when i reread it.
Reply With Quote
(#14 (permalink))
Old
Member
fididdly is on a distinguished road
 
Posts: 57
Join Date: Nov 2009
Default 05-10-2012, 03:29 PM

I don't quite understand what you mean, tomyam.

I wound up going to mycontactform.com. Their version worked.
Reply With Quote
(#15 (permalink))
Old
Junior Member
tomyam is on a distinguished road
 
Posts: 4
Join Date: May 2012
Default 05-10-2012, 06:54 PM

Thank you. I will give it a try!
Reply With Quote
(#16 (permalink))
Old
Junior Member
Toctiz is on a distinguished road
 
Posts: 15
Join Date: Jan 2012
Default 05-11-2012, 07:31 PM

i got it working but when submit is clicked it submits the message to my email but the page redirects to error 404

[24 minutes later]

Quote:
Originally Posted by Toctiz View Post
i got it working but when submit is clicked it submits the message to my email but the page redirects to error 404
its ok i fixed it now seems i typed the landing page address wrong

Last edited by d3iti; 05-12-2012 at 09:14 AM.
Reply With Quote
(#17 (permalink))
Old
Member
stannwl is on a distinguished road
 
Posts: 38
Join Date: May 2012
Default 05-12-2012, 11:54 AM

Hi All,

Can i know how can i get additional information to show on the body? Currently, the code posted by RibbitHost only shows the information entered under "Message". I can't the body to show others information like Name and Email.

Appreciate for any help offer

Stanley
Reply With Quote
Reply

Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com