dragon321723 2013-08-29 05:15
浏览 30

单击“提交”时验证textarea

I am developing website that allow user sending feedback to system. I have created feedback form by using textarea and button for submit. In most important thing is when user click on submit, if user input some words that I don't want them to input, that feedback won't send to the system; it will alert user to drop out that word before cicking submit.

Since now, i just create a simple code that will echo some warning if user input the word that i don't want them to input in feedback form.

Here is my code

<form action="main.php" method="post">
    <textarea cols='10' rows='5' name='text'></textarea>
    <br/>
    <input type='submit' name='add' Value='Add to list' />
</form>

<?php
if (isset($_POST['add'])) {
    $banned = array('dog', 'cat', 'cow'); // Add more
    $entry = $_POST['add'];
    foreach($banned as $word): if (strpos($entry, $word) !== false) die('Contains banned word');
    endforeach;
}
?> 

It is not work. Can anyone help me to solve this problem?

Thank in advance.

  • 写回答

6条回答 默认 最新

  • duanan1946 2013-08-29 05:17
    关注

    Try like

    $entry = $_POST['text'];    // Not $_POST['add'];
    foreach ($banned as $word):
        if (strpos($entry, $word) !== false) {
            echo 'Contains banned word';
            exit;
        }
    endforeach;
    

    Your $entry will be the text box value i.e. $_POST['text'] not $_POST['add']

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题