Click to See Complete Forum and Search --> : Very simple feedback form, please help to the noob!
cold.rain
11-28-2007, 01:35 PM
Hi all,
here my simple code:
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['text'];
$comment = $_REQUEST['comment'];
mail( "mymail@xyz.xz", "Feedback Form",
$name, $comment, "From: $email" );
header( "Location: http://www.megawhite.au" );
?>
I need to check, if ALL of the fields are filled. If yes - then go to www.megawhite.. if NOT - to some other www.
I know, that it is somehow possible with "empty" command.. :rolleyes:
Can You put tags on the right way, please?
Thanx.
blue-eye-labs
11-28-2007, 01:53 PM
you can check if a variable is empty using if(empty($var1)) { ... } or alternatively: if(!$var1) { ... } which is the method I use.
cold.rain
11-28-2007, 02:57 PM
so, how the whole code could look like?
if(!$name) && {!$email} && && {!$comment} are empty... etc.
blue-eye-labs
11-28-2007, 03:23 PM
$formHref = "/form.php"; //the location of your original form
$afterHref = "/thankyou.php" //the location of the "thank you" page or some such
$name = $_REQUEST['name'];
$email = $_REQUEST['text'];
$comment = $_REQUEST['comment'];
if(!$name || !$email || !$comment) {
echo "Please completely fill out the form";
header("Location: " . $formHref);
} else {
mail( "mymail@xyz.xz", "Feedback Form", $name, $comment, "From: $email" );
header( "Location: " . $afterHref );
}
cold.rain
11-29-2007, 04:09 PM
thanx, this was really helpful.
i have used just the simple part, look what i have now:
if(!$name || !$email || !$comment) {
header("Location: http://www.xx.oo");
} else {
mail("xxx@xx.xx", "Feedback Form Results",
$name, $comment, "From: $email");
header("Location: http://www.xx.pp");
}
but - why it does not showing the correct sender's mail (the one he writes in "email" field)? it shows the mail, i have indicated in my hosting options.
blue-eye-labs
11-29-2007, 04:54 PM
the email will always come from the CGI mailer or whatever your servers mail() command tells to send the email. It won't show up as from someone else. I suppose that you could try and use a "Reply-to:" header somehow. It should display their email address within the email that is sent to your mailbox.