防止html表单字段中的链接

mal*_*lly 3 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>
Run Code Online (Sandbox Code Playgroud)

小智 5

在插入数据库之前添加它

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
}
Run Code Online (Sandbox Code Playgroud)