Jump to content

Simple Enough question, but i really need help =)


shisamandisa

Recommended Posts

Hey, I have a fully functionaly contact.php file that submits me data from my website, but unfortunately people are able to just click submit as many times as they want and it will send to me a blank email. Is there a way to stop this? Like if someone does not fill in the form then it will not be sent and redirect to an error page this is what i have so far if someone were to correct me and fill in what i need to do this i would be greatly appreciative. thanx!

*No real sites, emails used fake ones for privacy reasons

[code]<?php
@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");
header("Location: anywebsite.com");
?>
[/code]

Now is there a code i can add to redirect my visitors to "errorwebsite.com" if they do not fill in 'username' or 'password'?
Link to comment
Share on other sites

You could/should do a couple of things

1. use some string functions like trim, and/or strlen to make sure the variable contain data.

2. you could also check to make sure the variables only contain certain characters, ie alphanumeric

3. use a captcha to add a little more protection

Lite...
Link to comment
Share on other sites

I like just started coding and i have no idea what any of that means so if anyone knows how to fix this and actually are able to write the code that would enable visitors to be redirected to a "errorsite.com" if they do not complete the form and click submit please do so, because suggestions and advise do nothing for me im noobish but thanks for any help!
Link to comment
Share on other sites

<?php

if((!$email=="none")&&($password=="none")&&($name=="none")){
echo " sorry fill in the dam form";

}elseif if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$email)) {

echo"please add a correct email address</a>";
}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");
header("Location: anywebsite.com");
?>
Link to comment
Share on other sites

would this work to or how would i do something more like this?

[code]<?php

if((!$username=="none")&&($password=="none")){
echo("Location: Errorsite.com");
}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");
header("Location: somesite.com");
?>
[/code]
Link to comment
Share on other sites

try this ok.

[code]
<?php

if((!$email=="none")&&($password=="none")&&($name=="none")){
echo " <font color='red'>sorry fill in the dam form</font>";

}elseif if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$email)) {

echo"<font color='red'>Please add a correct email address</font>";
}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");
header("Location: anywebsite.com");
?>
[/code]
Link to comment
Share on other sites

<?php

if((!$email=="none")&&($password=="none")&&($name=="none")){

header(location: what_ever.com");

}elseif if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$email)) {

header(location: what_ever.com");

}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");

header("Location: anywebsite.com");
}
?>
Link to comment
Share on other sites

why would i need

[code]if((!$email=="none")&&($password=="none")&&($name=="none")){

header(location: what_ever.com");

}elseif if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$email)) {

header(location: what_ever.com");

}[/code]

i have only username and password option so would it be like this?

[code]if((!$username=="none")&&($password=="none")){

header(location: what_ever.com");

}elseif if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$email  *There is no email option what should go here?)) {

header(location: what_ever.com");

}[/code]
Link to comment
Share on other sites

np thanks for helping me tho! if i did want to have a reply "echo" would this be correct?

[code]<?php

if(!$username="none")&&(!$password="none")){

echo "<font color="white"><b>Invalid Username or Password</b></font>";

}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");
header("Location: site.com");
?>
[/code]
Link to comment
Share on other sites

<?php

if(!$username="none")&&(!$password="none")){

echo "<font color='white'><b>Invalid Username or Password</b></font>";

}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");
header("Location: site.com");
?>


"  '  ' " double quote single quote ect ect ect ok
Link to comment
Share on other sites

== sorry edited ( sorry
<?
if((!$username=="none")&&(!$password=="none")){

echo "<font color='white'>Invalid Username or Password</font>";

}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");
header("Location: site.com");
?>
Link to comment
Share on other sites

try that ok
<?
if((!$username=="none")&&(!$password=="none")){

echo "<font color='white'>Invalid Username or Password</font>";

}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");

if(($username)&&($password)){
header("Location: site.com");
}
?>
Link to comment
Share on other sites

sweet thanks we are get much closer and i owe u for this. the only problem is....

[code]<?
if((!$username=="none")&&(!$password=="none")){
header("Location: error.html");

}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");

if(($username)&&($password)){
header("Location: header.html");
}
?>[/code]

If someone doesnt fill out anything it will redirect them to the error page and if they do fill it in it will redirect them to the thank you page, but is their a way to not have a blank email sent if they dont fill it out because even tho the are redirected to an error (please fill out form) page the unfinished form is still sent
Link to comment
Share on other sites

try this ok

<?
if((!$username=="none")&&(!$password=="none")){
header("Location: error.html");
exit;
}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];
mail("email@gmail.com", $username, $password, "From: $username");

if(($username)&&($password)){
header("Location: header.html");
exit;
}
?>

added exit ok if error
Link to comment
Share on other sites

<?
if((!$username=="none")&&(!$password=="none")){
header("Location: error.html");
exit;
}

@extract($_POST);
$username=$_POST['username'];
$password=$_POST['password'];

if($_POST['submit']){

mail("email@gmail.com", $username, $password, "From: $username");

if(($username)&&($password)){
header("Location: header.html");
}
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.