Forum Moderators: coopster
I'm still very much learning this:)
<?
if(!($make && $model && $engine && $Year && $from)){
?>
You have not entered Make, Model, Engine, Year or Email Address. Please click back button and enter.
<?
//Check email is valid
}elseif(!(ereg("^.+@.+\\..+$",$from))){
?>
<?=$from?> is not a valid email address. Please click back button and enter
<?
}else{
$emailmessage = "EBC Products Addition\n\n";
$emailmessage .= "Make : $make\nModel : $model\nEngine : $engine\nReg : $Reg\nYear : $Year\n";
$emailmessage .= "Spec : $Spec\nABS : $ABS\nEmail : $from\nGreenstuff : $Greenstuff\nRedstuff : $Redstuff\n";
$emailmessage .= "Turbo-Groove : $TurboGroove\nFront : $Front\nRear : $Rear\n";
if(mail("sales@example.com","EBC Product Addition Request","$emailmessage","From:$from","-fsales@example.com")){
//echo "work - email";
}else{
echo "email not worked";
}
?>
Thank you for your interest in :snip Products. It will help us to understand which products you would like to be made available on our sites.
<?
}
?>
I think I know how to rewrite this. Maybe I should.
<?php
//create short variable names
$make=$_POST['make'];
$model=$_POST['model'];
$engine=$_POST['engine'];
$reg=$_POST['reg'];
$year=$_POST['Year'];
$type=$_POST['Spec'];
$abs=$_POST['ABS'];
$from=$_POST['from'];
//set up some static information
$toaddress = "example@example.com";
$subject = "Feedback from web site";
$mailcontent = "Make: ".$make."\n".
"Model: ".$model."\n".
"Engine Size: ".$engine."\n".
"Vehicle Registation: ".$reg."\n".
"Year Of Manufacture: ".$year."\n".
"Origin: ".$type."\n".
"ABS Equiped: ".$abs."\n".
"Email Address: ".$from."\n";
$fromaddress = "From: $from";
//invoke mail() function to send mail
mail("$toaddress","$subject","$mailcontent","$fromaddress")
?>
[edited by: GGR_Web at 2:27 pm (utc) on May 19, 2009]
<FORM METHOD="post" ACTION="notlisted_reply.php">
The default method of a form is get, but since you specified a method you will be looking in post.
var $checkboxes=Array ('a','b','c','d');
foreach ($checkboxes as $key) {
if (isset($_POST[$key])) {
// sanitize and process $_POST[$key]
}
}
A checkbox value will not be sent in $_POST/$_GET/$_REQUEST if it's not checked, so you only have to check if it's been set.
Why do I need a foreach function when it seems I can call values out of the array?
For the moment I've got
"Product Required: ".$product[0]." ".$product[1]." ".$product[2]."\n".
Which is semi-working, but isn't returning the first ticked value for some reason. I'll try putting in a hidden input to overcome that.
I'm hitting a blank screen when I submit the form.
Put at the top of your script:
error_reporting(E_ALL);
ini_set('display_errors', '1');
This will reveal other things, including non-fatal warnings, and help you code more strictly.
Why do I need a foreach function when it seems I can call values out of the array?
Example only, to demonstrate how you'd check for input values. Sure you could just pull the values. The foreach is useful if you want to make sure at least one is checked, or compare input against preset values for security reasons (i.e., any input for these values will be of the types I define, not some mySQL injection attempt, etc. . . )
The point is the values will only be present in $_POST (if your form method is post) if the boxes are checked.
Do I need to call $key with $key or $key[0]?
No, the previous example presumes your form output is this:
<input type="checkbox" name="a" id="a" value="1">
<input type="checkbox" name="b" id="b" value="2">
<input type="checkbox" name="c" id="c" value="3">
<input type="checkbox" name="d" id="d" value="4">
If anything besides what's posted, you'd do
var $a = $_POST['a'];
var $b = $_POST['b'];
.........