html - 防止 html 表单字段中的链接

标签 html forms hyperlink

如果表单包含链接,是否有办法阻止提交表单。 我想阻止将链接添加到输入:问题和消息字段。

任何人都可以指出正确的信息方向吗? 谢谢

<div class="form">
        <form id="sbwd_contact" method="post" action="http://whatanswered.com/forms/ask/ask.php">
            <em class="error"></em>
            <input type='hidden' name='sfm_form_submitted' value='yes'/>
            <label for="Email">E-Mail: </label>
            <input type="text" id="Email" name="Email" size="30" class="required email" />
            <label for="question">Question: </label>
            <input type="text" id="question" name="question" size="30" class="required" />
            <label for="Message">Additional Info: </label>
            <textarea name="Message" cols="30" rows="6" id="Message" class="required"></textarea>
            <br />
            <p><span>I Agree to the Terms and Conditions
                        <input type="checkbox" name="Terms_and_conditions" value="I agree" class="required"/></span></p>
            <input name="Submit" type="submit" id="Submit" value="Send" />
            <br /><br />
            <p><a href="http://whatanswered.com/terms-and-conditions.php" target="_blank">View our Terms and Conditions</a></p>
        </form>

最佳答案

在插入数据库之前添加这个

if(preg_match("/\b(?:(?:https?|ftp|http):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$_POST['question'])){

// prevent form from saving code goes here
 echo "<script>alert('Please remove URLs');</script>"; 
}
else{
 // Insertion in Db
}

关于html - 防止 html 表单字段中的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16598720/

相关文章:

python - 使用 Python 而不是 HTML 从网站中提取链接

jquery - 第一列固定的表格滚动

html - 折叠时 Bootstrap 列的顺序

node.js - 如何在 Node Express 中将表数据存储在缓存中?

html - 表单内的不同 radio 样式

java - 无法单击 Selenium Webdriver 中的所有链接。仅单击第一个链接

html - 如何仅使用 CSS 和 HTML 制作返回顶部按钮?

javascript - 如何使用 javascript 异步移动多个叠加图像?

c# - 我可以提交仅包含隐藏字段的表单吗?

html - 跳转页面超链接不起作用。