所以我已经使用过这个网站很长一段时间了,以前从来没有问过,但是我把头发拉了出来!请帮帮我。
我使用简单脚本,我发现使用表单将结果发送到电子邮件地址。要开始验证2个字段已满,不要让它发送,虽然字段保存数据 - 所以我删除该条件,它将发送电子邮件,但它不会显示实际数据显示。你能看一下并建议吗?
我的PHP:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name - $_POST['name'];
$description - $_POST['description'];
$car_year - $_POST['car_year'];
$big_brakes - $_POST['big_brakes'];
$road_car - $_POST['road_car'];
$type - $_POST['type'];
$email - $_POST['email'];
//Validate first
if(empty($name)||empty($email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'marketing@part-box.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $name".
$to = "marketing@part-box.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RAYS Wheels Quote</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>RAYS Wheels Quote</a></h1>
<ul >
<center><img src="images/Rays---Coming-soon-page_03.jpg" width="251" height="72" alt=""></td></center>
</ul>
<form method="post" name="myemailform" action="form-to-email.php">
<div class="form_description">
<center><p>Free Quote for RAYS Wheels, Give us the information we have asked for and we will find the Wheels for your Car.</p></center>
</div>
<ul >
<li id="li_1" >
<label for="name">name</label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_2" >
<label for="description" >Car Make and Model</label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_6" >
<label for="car_year">Car Year</label>
<div>
<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label for="big_brakes" >Big Brakes Fitted? Yes / No</label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label for="road_car">Road Car / Motor sport?</label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_5" >
<label for="type" >Type of RAYS Wheel</label>
<div>
<input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<label class="email" >Your Email Address</label>
<div>
<input id="element_5" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="793428" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("myemailform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<div id="footer"></a>
<center><center><img src="images/Rays---Form-Footer.jpg" width="624" height="264" alt="Makes"></td></div>
</div></center>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
答案 0 :(得分:0)
<强> PHP 强>
从中改变:
$name - $_POST['name'];
$description - $_POST['description'];
$car_year - $_POST['car_year'];
$big_brakes - $_POST['big_brakes'];
$road_car - $_POST['road_car'];
$type - $_POST['type'];
$email - $_POST['email'];
到此:
$name = $_POST['name'];
$description = $_POST['description'];
$car_year = $_POST['car_year'];
$big_brakes = $_POST['big_brakes'];
$road_car = $_POST['road_car'];
$type = $_POST['type'];
$email = $_POST['email'];
<强> HTML 强>
从此改变:
<label for="name">name</label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_2" >
<label for="description" >Car Make and Model</label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_6" >
<label for="car_year">Car Year</label>
<div>
<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label for="big_brakes" >Big Brakes Fitted? Yes / No</label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label for="road_car">Road Car / Motor sport?</label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_5" >
<label for="type" >Type of RAYS Wheel</label>
<div>
<input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<label class="email" >Your Email Address</label>
<div>
<input id="element_5" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div>
To This:
<label for="name">name</label>
<div>
<input id="element_1" name="name" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_2" >
<label for="description" >Car Make and Model</label>
<div>
<input id="element_2" name="description" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_6" >
<label for="car_year">Car Year</label>
<div>
<input id="element_6" name="car_year" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label for="big_brakes" >Big Brakes Fitted? Yes / No</label>
<div>
<input id="element_3" name="big_brakes" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label for="road_car">Road Car / Motor sport?</label>
<div>
<input id="element_4" name="road_car" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_5" >
<label for="type" >Type of RAYS Wheel</label>
<div>
<input id="element_5" name="type" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<label class="email" >Your Email Address</label>
<div>
<input id="element_5" name="email" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<强>解释强>
在PHP中,从$_POST
变量设置值时,将减号更改为等号。
在HTML中,输入的值将传递给PHP脚本将基于name
属性。因此,为了在提交后传递值,HTML代码如下:
`<input id="someid" name="test" />`
将作为
传递给PHP$_POST['test']