无法验证文本区域 [英] Unable to validate textarea

查看:91
本文介绍了无法验证文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法验证下面的文本区域,不知道我的代码有什么问题.

I am unable to validate the textarea below, don't know what's wrong with my code.

<div id="chooseForm">
    <input type="checkbox" name="ArticlesOrderForm" value="ArticlesOrderForm">
    <b>Articles Order Form </b>
</div>';





$echo .= '  <script>
        jQuery(function($) {
            $(".formGroup").hide();
            $("#chooseForm input:checkbox").on("change", function() {
                if($(this).is(":checked")) {
                    $("#" + $(this).val()).show();
                }
                else {
                    $("#" + $(this).val()).hide();
                }
            });
        });

    </script>';





     $echo .=  '<div id="ArticlesOrderForm" class="formGroup">
                <legend>Articles Order Form</legend>
                <b><label for="article_keywords">Keywords/Titles<span class="reqd">*</span> : </label></b> <textarea rows="6" cols="50" id="article_keywords" name="article_keywords" > </textarea>
            </div>';
<br/><br/>

if($_POST['ArticlesOrderForm'] == 'checked') {  

  if(!isset($_POST['article_keywords']) || empty($_POST['article_keywords'])) {
    $myerror= '<li>'.__('<strong>Keywords/Titles</strong> - missing.','article_keywords').'</li>';
    }   
}



如果有人不输入该文本区域,我应该得到一条消息关键字/标题-丢失". 谁能告诉我我的逻辑有什么问题吗?



I should get a message 'keywords/titles - missing' if someone does not enter into that text area.. Could anyone please tell me whats wrong in my logic?

请在此处找到完整的代码: http://jsfiddle.net/DTcqk/3/ 此处: http://jsfiddle.net/YYAbm/

Please find the full codes here : http://jsfiddle.net/DTcqk/3/ and here: http://jsfiddle.net/YYAbm/

推荐答案

默认情况下,您的文本区域不为空:

Your textarea is not empty by default:

<textarea rows="6" cols="50" id="article_keywords" name="article_keywords" > </textarea>
                                                    you have space here ----^

因此它不会输入您的以下if:

So it won't enter your following if :

if(!isset($_POST['article_keywords']) || empty($_POST['article_keywords'])) {

如果要在验证if中仅捕获带有空格的变量,则应使用trim(),例如:

You should use trim() if you want to catch variables with only spaces in your validation if, like so:

$_POST['article_keywords'] = trim($_POST['article_keywords']);
if(!isset($_POST['article_keywords']) || empty($_POST['article_keywords'])) {

这篇关于无法验证文本区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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