FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Contact Form prob





riyadh
i wrote a contact form for my site.i don knw how to process the form in such a way tht if the user enter s the incorrect/correct security code, they are able to submit the form successsfully.the code is given below.

code for the form
Code:

<form action="send.php" method="post" name="ContactForm" id="ContactForm">
               <tr><td><label>Name<font class="required">*</font>:</label></td><td><input type=text class="input" name="name" id="name" style="width:300px;"></td></tr>
               
               <tr><td><label>Email<font class="required">*</font>:</label></td><td><input type=text class="input" name="email" id="email" style="width:300px;"></td></tr>
               
               <tr><td><label>Message<font class="required">*</font>:</label></td><td><textarea type=text class="input" name="msg" id="msg" rows=200 cols=55 style="height:200px;width:300px;" wrap="VIRTUAL"></textarea></td></tr>
               
               <tr><td>&nbsp;</td><td><img src="security-image.php?width=144" width="144" height="30" alt="Security Image" style="border: 1px solid #878A8C" /></td></tr>
               
               <tr><td><label>Security Code<font class="required">*</font>:</label></td><td><input type="text" class="input" name="code" id="code" value="" style="width:300px;" /></td></tr>
               
               <tr><td>&nbsp;</td><td><input type=submit class="button" name="submit" value="Submit" id="submit">&nbsp;&nbsp;&nbsp;<input type="reset" class="button" name="reset" value="Clear"></td></tr>
               </form>


code for send.php
Code:

<?php

$subject ="Contact Us Form";
$message="$msg";
$mail_from="$email";
$name="$name"; 
$header="from: $name <$mail_from>";

$to ='email@domain.com';

$send_contact=mail($to,$subject,$message,$header);

if($send_contact){
header('Location: suc.php');
}
else {
header('Location: unsuc.php');
}
?>
alalex
ok, so there we go:

First you need to have several images, identified by their source. Then save in a database the list of images by their source, and the code.
The way it is going to work is the following: you will have php display a random image from the ones you have. Then, store the source for that image in a hidden field i will call "source"

Once the form is submitted, using php you will open up the database, and retrieve the secret code that assigned to that image ( you know which image is because you have its source in $_POST['source'] ) So that now you can just compare the source code you just retrieved from the databse with the one entered by the user.
And that's it!
If you have any more questions, or you run into any problems doing this, post it in this same post!
Luck Wink
riyadh
i'm not using a database and i don need to use one since the security images being generated r random and it will take up a lot of space and server time if i link it with a database.is isn't there another way around this?
alalex
sure, you can write an array in php that contains the image source (numbered from 0 on) and as the value for each you would have the security code:
Code:
$security = array(1 => '15FGDS', 2 => '4RTEG3', 3 => 'JKHS882');


So that now you have the security code. I would also encrypt those security numbers using sha1, but that's up to you. Before you send the form, you could use a session variable to store the encrypted security code from the array, so look at this code;
Code:

//I will suppose that the array has been already setup and that the stored secrity numbers are in sha1
$random = 3; //this is the randomly generated number
$num = $security[$random]; //Get the encrypted security num.
$_SESSION['sec_num'] = $num; //Store that num to a session.

Now the form is submitted:
Code:

//this is the next page, once the form has been submitted:
//first, get their number to sha1:
$s_num = sha1($_POST['code']);
if($s_num == $_SESSION['sec_num']){
echo 'Security image matched!'; //the numbers are the same
}else{
echo 'The security code is not correct'; //the numbers were not the same!
}


So this way you have it pretty much done! Check the syntax, since i didnt really pay much attention to it, but the idea is clear.
Wink
Agent ME
riyadh wrote:
i'm not using a database and i don need to use one since the security images being generated r random and it will take up a lot of space and server time if i link it with a database.is isn't there another way around this?

It's quicker to connect to a database than randomly generate an image iirc...

I'm not saying you should use a database, but that argument is like saying it's safer not to put on your seatbelt when you drive because it distracts you too much while you put it on (even though it only takes at most 2 seconds to put on).
alalex
nice example Agent ME
Agent ME wrote:
is like saying it's safer not to put on your seatbelt when you drive because it distracts you too much while you put it on (even though it only takes at most 2 seconds to put on).


Very Happy Smile Laughing
good one Wink
Related topics
contact form
Need a simple Contact form
For those who need a contact form
I am trying to build a contact form using php and flash
contact form with IP feature ?
AJAX and PHP contact form
Need a Contact form from HTML/PHP
Need help to make my Flash contact form functioning!
Easy Contact Form with Instructions
Spam protection for contact form?
Contact form or email address?
Wordpress Contact Form 7 not appearing on Custom Theme
Contact Form Issues
Create a Flash Contact form, sends to your email account
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.