douxianxing5712 2016-09-02 01:59
浏览 33

HTML页面中的PHP回显

I have a contact.html page I have a form on. The form action goes to .php page to handle the email, nothing special. On that page I have:

<?php
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

$FirstName = check_input($_REQUEST['FirstName']);
$LastName = check_input($_REQUEST['LastName']);
$email = check_input($_REQUEST['email']);
$phone = check_input($_REQUEST['phone']);
$message = check_input($_REQUEST['message']);
$human = check_input($_REQUEST['human']);
$webpackage = check_input($_REQUEST['webpackage']);
$webdesign = check_input($_REQUEST['webdesign']);
$customdesign = check_input($_REQUEST['customdesign']);

if ($human == 5) {

$to = "****.com";
$subject = "From ****";

$body = " From: $FirstName  $LastName

 E-Mail: $email

 Phone:     $phone

 Message:

 $message

 Web Package:$webpackage

 Web     Design:$webdesign

 Custom Design:$customdesign";


mail ($to, $subject, $body);
header('location: index.html');
}
else {
$result="<div class=\"alert alert-danger\">Sorry there was an error sending     your message. Please go back and check your anti-spam answer</div>";
}

?>

I have a simple box that equals 5 that I am checking value for. This works and email sent with all info. BUT if not equal to 5 is where the problem starts. The page goes to my action.php page and is blank.

My html on the contact.html page is:

    <div class="form-group">
                <div class="col-sm-10 col-sm-offset-2">
                    <?php echo($result); ?>
                </div>
            </div>

Using this to get to my action.php page through form. Everything else is .html:

 <form class="form-horizontal" id="contact-form" method="post" action="/action.php">

Is there a way to do this? I have a work around where I just echo the error from the .php page. This works if !=5 but not exactly what I want to do. As you may tell, I am not PHP literate.

  • 写回答

3条回答 默认 最新

  • dongyong6045 2016-09-02 02:13
    关注

    You can set a variable in the $_SESSION[] array, and in your "else" section use Header() to redirect to a page where you display the value you stored.

    See example in this other answered question:

    displaying a message after redirecting the user to another web page

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程