duanchongzi9997 2019-05-11 11:30 采纳率: 0%
浏览 61
已采纳

如何在结果回显之前添加表单验证回显

I have a form in php which works just fine, except that the user can see result without providing email and name fields. I want to add a php code that will echo to user that name and email is required before he gets to see the final answer. I have tried adding various if and else statements but the form stops working if i fiddle with the code. I would b really grateful for some help

<?php 
$name = $_POST['fieldname5_1'];
$email = $_POST['fieldname6_1'];
$score = $_POST['fieldname158_1'];
if(empty($name) || empty($email))
{
echo "You did not fill out the required fields.";

}
else {
if($score<"6") {
echo " something1 $score";
} elseif($score<"11") {
echo " something2 $score";
} elseif($score<"30") {
echo " something3 $score";
} elseif($score<"81") {
echo " something4 $score";
}  else {
echo " something5 $score";
}
}
$formcontent="something6 $score";
$recipient = "myemail@email.com, $email";
$subject = "Your test";
$mailheader = "From: myemail@email.com 
";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

?>
  • 写回答

2条回答 默认 最新

  • dongzhong8834 2019-05-11 12:11
    关注

    if this html form u can add "required" to input? or in js if form submited check fields , if all ok, your POST will go to php action/method

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记