sonicthehedgehog Posted September 14, 2015 Share Posted September 14, 2015 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 More sharing options...
niche Posted September 14, 2015 Share Posted September 14, 2015 http://php.net/manual/en/function.isset.php Link to comment Share on other sites More sharing options...
Ingolme Posted September 14, 2015 Share Posted September 14, 2015 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 More sharing options...
sonicthehedgehog Posted September 15, 2015 Author Share Posted September 15, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now