Jump to content

Checking if post is empty


sonicthehedgehog

Recommended Posts

Is it possible to check for a text value as part of the a post element? Each input field has a name of style_ along with an id number, but how do I check to see if they're empty?

This works:

<?=(!empty($_POST['style_22'])?' checked':'')?>

but as style_ is text but the number changes every time and this doesn't work:

<?=(!empty($_POST['style_['id']'])?' checked':'')?>

It just gives me an error.

Link to comment
Share on other sites

The <?= ?> syntax is deprecated and may not work on all PHP servers. Use the correct expression <?php echo ?>

 

If you want to use a variable in the index of an array, just concatenate it. The index of an associative array is a string. Like this:

$id = 5;echo !empty($_POST['style_' . $id]) ? ' checked' : '';
Link to comment
Share on other sites

 

The <?= ?> syntax is deprecated and may not work on all PHP servers. Use the correct expression <?php echo ?>

 

If you want to use a variable in the index of an array, just concatenate it. The index of an associative array is a string. Like this:

$id = 5;echo !empty($_POST['style_' . $id]) ? ' checked' : '';

Thank you I'll give that a go

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...