如果表单包含链接,是否有办法阻止提交表单。 我想阻止将链接添加到输入:问题和消息字段。
任何人都可以指出正确的信息方向吗? 谢谢
<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/