Reputation: 152
I have a textarea field and want to add a text or php code when the field is empty and if the field is not empty to add another php code. For example:
if the field is empty>do something.....else>do something...
I'm not good at php, so I'll be glad for any help. Thanks.
p.s.Sorry for my english.
Upvotes: 0
Views: 5079
Reputation: 157864
To test if outside variable is empty or not, you can just compare it with empty string
if ( $_POST['text'] === '') {
echo 'there was something';
} else {
echo 'nothing to say';
}
Upvotes: 1
Reputation: 13947
Assuming you're posting this from a form then you can do the following.
I'll write this out the long way so it's easier to understand:
if (!empty($_POST['TEXTAREA_NAME']){
// If the textarea is set then do something here
} else {
// If it is NOT set it then it will do the code here
}
Upvotes: 2
Reputation: 3539
<?php echo isset($_POST['texarea_name']) && !empty($_POST['texarea_name']) ? 'textarea not empty' : 'texarea is empty'; ?>
Upvotes: 2