元素窗体上属性操作的值不正确:必须为非空值 [英] Bad value for attribute action on element form: Must be non-empty

查看:84
本文介绍了元素窗体上属性操作的值不正确:必须为非空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的php文件中有一个常规表单,提交后它必须回显一条消息。
通过在action =中放入任何东西,我可以考虑显示消息的唯一方法是将其存储到会话中,并在页面加载时显示它(如果存在会话集)。

I have a regular form on my php file, after it's submitted it has to echo a message. By putting anything in the action="", the only way I can think of displaying a message is by storing it into a session and display it when the page loads if there is a session set.

现在一切正常,但w3c验证器说我有一个错误:

Everything works fine the way it is right now but w3c validator says I have an error:


Bad value for attribute action on element form: Must be non-empty.

如何解决这个错误,而不必将#或index.php进入动作字段?

How can I fix this error without having to put # or index.php into the action field?

编辑:

<form action="" method="post">
    <input type="email" name="email" placeholder="Enter your email">
    <input type="submit" name="submit" value="SEND">
</form>

<?php
    if(isset($_POST['submit']) && isset($_POST['email'])){          
        if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){
           echo 'This isn\'t a valid email';
        }else{
           echo 'Great';
        }
    }
?>


推荐答案

W3C HTML Checker(验证器)的维护者。如果你的目标是让检查者不发出那个错误,那么一种方法是继续,并把作为 action 属性,然后使用JavaScript将其删除,如下所示:

Maintainer of the W3C HTML Checker (validator) here. If your goal is just to get the checker to not emit that error, one way to do that is to go ahead and put # as the value for the action attribute in your HTML source, but then remove it using JavaScript, like this:

<form action="#" method="post">
    <script>document.querySelector("form").setAttribute("action", "")</script>
    <input type="email" name="email" placeholder="Enter your email">
    <input type="submit" name="submit" value="SEND">
</form>

这篇关于元素窗体上属性操作的值不正确:必须为非空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆