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?
Please find the full codes here : http://jsfiddle.net/DTcqk/3/
and here: http://jsfiddle.net/YYAbm/
Your textarea is not empty by default:
So it won’t enter your following
if:You should use
trim()if you want to catch variables with only spaces in your validationif, like so: