无法验证文本区域

编程入门 行业动态 更新时间:2024-10-27 12:26:33
本文介绍了无法验证文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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?

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

Please find the full codes here : jsfiddle/DTcqk/3/ and here: jsfiddle/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'])) {

更多推荐

无法验证文本区域

本文发布于:2023-11-10 00:30:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   区域

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!