Newbie
Newbie

Reputation: 152

Check textarea with php

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

Answers (3)

Your Common Sense
Your Common Sense

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

SpaceBeers
SpaceBeers

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

Vytautas
Vytautas

Reputation: 3539

<?php echo isset($_POST['texarea_name']) && !empty($_POST['texarea_name']) ? 'textarea not empty' : 'texarea is empty'; ?>

Upvotes: 2

Related Questions