| Coding Forum Problems with your code? Let's hear about it. |
05-10-2008, 03:24 PM
|
#1 (permalink)
|
|
Junior Member
Join Date: 05-07-08
Posts: 4
Latest Blog: None
|
Need help with contact form
I have added a contact form to my site and it seems to be working. What I would like to do know, is add some type of feature were an individual is limited on the number of times they can submit my form over a given time interval(lets say five minutes).
Below you will find my contact form and contact.php file.
Code:
contact form
<form id="form" method="post" action="contact.php" enctype="multipart/form-data" name="form">
<strong><u>All fields marked * are required</u></strong>
<br /><br style="line-height:15px;" />
<div class="col_box">
<div class="col_box_1">
<strong>Subject</strong>
<div class="t_form"><input name="content" type="text" value="" /></div>
<strong>Name *</strong>
<div class="t_form"><input name="visitor" type="text" value="" /></div>
<strong>Email *</strong>
<div class="t_form"><input name="visitormail" type="text" value="" /></div>
<br /><br style="line-height:3px;" />
<strong><a href="http://www.***.com/verification.html" onclick="window.open('http://www.***.com/verification.html','popup','width=400,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">whats this?</a></strong>*<img src="captcha.php"><input type="text" name="vercode" value="Place above code here" /><br>
</form>
</div>
<div class="col_box_2">
<strong>Message *</strong>
<textarea name="details" cols="2" rows="2" ></textarea>
<strong style="margin:0 15px 0 40px;">
<input type="submit" name="submit" value="Submit"><input type="reset" name="Submit2" value="Reset"> </div>
<div class="clear"></div>
</div>
</form>
</div>
Code:
contact.php file
<?php
$content = $_POST['content'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$details = $_POST['details'];
if (eregi('http:', $details)) {
die ("We don't allow visitors to submit website links due to security reasons, Please click the browser back button and remove the link.");
}
if(empty($visitor) || empty($visitormail) || empty($details )) {
echo "<h2>Use the browser back button and fill in all required form fields</h2>\n";
die ("");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use browser back button and enter a valid e-mail address</h2>\n";
$badinput = "<h2>A valid email looks like this: someone@someone.com</h2>\n";
echo $badinput;
die ("");
}
session_start();
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
echo "<h2>Use browser back button and enter the correct verification code.</h2>\n";
die ("");
}
$todayis = date("l, F j, Y") ;
$content = $content ;
$subject = $content;
$details = stripcslashes($details);
$message = " $todayis \n
Subject: $content \n
Message: $details \n
From: $visitor ($visitormail)\n
";
$from = "From: $visitormail\r\n";
mail("email@email.com", $subject, $message, $from);
?>
<p align="center">
Date: <?php echo $todayis ?>
<br />
Email was recieved - Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />
Subject: <?php echo $subject ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $details);
echo $notesout; ?>
<br />
<br /><br />
<a href="contactus.html"> Back to contact page </a>
</p>
Any help would be greatly appreciated.
If you also notice anything else that can be added or changed please let me know
Thanks
Last edited by gordon : 05-10-2008 at 03:36 PM.
|
|
|
05-10-2008, 03:45 PM
|
#2 (permalink)
|
|
v7n Mentor
Join Date: 07-24-06
Posts: 642
Latest Blog: None
|
When submitting the form simply set cookie with a 5 minutes lifetime (if such does not exist yet). If cookie already exist display warning or whatever you want.
|
|
|
05-11-2008, 03:11 PM
|
#3 (permalink)
|
|
Junior Member
Join Date: 05-07-08
Posts: 4
Latest Blog: None
|
I did some searching and I found this:
setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] )
Is this what I have to put in my contact.php file.
Also could you help me figure out what code goes into my contact form.
Thanks
|
|
|
05-12-2008, 09:59 AM
|
#4 (permalink)
|
|
Contributing Member
Join Date: 04-22-08
Posts: 99
Latest Blog: None
|
|
|
|
05-12-2008, 05:41 PM
|
#5 (permalink)
|
|
Junior Member
Join Date: 05-07-08
Posts: 4
Latest Blog: None
|
I have added this code to my contact.php file:
Code:
setcookie("contact", "contactform", time()+3600);
if ($_POST["contactform"]) ; {
echo "<h2>You must wait one hour, before submitting more information via the contact form.</h2>\n";
die ("");
}
What I would like to happen is for a cookie to be placed on the visitors computer when they first submit the form(This seems to have been accomplished). I want to do this to prevent the visitor from spamming my inbox.
What I would like to happen now is have the php file display an error message if the cookie already exists on the visitors computer. As it stands now i get the above error message "You must wait one hour, before submitting more information via the contact form". even if the cookie is non existent. So can someone please help me figure this out.
I will also like the cookie to expire after 5 minutes, but i have no idea what the time value needs to be changed to.
Thanks
Gordon
|
|
|
05-13-2008, 11:29 AM
|
#7 (permalink)
|
|
Possible Terrorist
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
|
change your code to this, you have a ; that is ending the if statement.. surprised that even compiles
Code:
setcookie("contact", "contactform", time()+3600);
if ($_POST["contactform"]) {
echo "<h2>You must wait one hour, before submitting more information via the contact form.</h2>\n";
die ("");
}
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
|
|
|
05-13-2008, 11:56 AM
|
#8 (permalink)
|
|
v7n Mentor
Join Date: 07-24-06
Posts: 642
Latest Blog: None
|
if ( $_COOKIE["contactform"]) {
echo "<h2>You must wait one hour, before submitting more information via the contact form.</h2>\n";
die ("");
}
setcookie("contact", "contactform", time()+3600);
P.S. if you set cookie and then immediately check if it exists - it will obviously exist Moved setcookie after if statement.
|
|
|
05-13-2008, 12:04 PM
|
#9 (permalink)
|
|
Possible Terrorist
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
|
Good call nasty.web, can't believe I didn't catch that.
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
|
|
|
05-13-2008, 04:44 PM
|
#10 (permalink)
|
|
Junior Member
Join Date: 05-07-08
Posts: 4
Latest Blog: None
|
Thanks for the help  My website is now complete.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 12:49 PM.
© Copyright 2008 V7 Inc
|