"Form input without an associated label or title attribute" when using dynamic IDs
Hello,
PhpStorm shows me that warning when using dynamic IDs for input fields.
Example code:
// .../admin/edit-user.php
<!-- header html and so on... -->
<?php $fields = [
'username' => [
'name' => 'Username',
'type' => 'text',
],
'password' => [
'name' => 'Password',
'type' => 'password',
],
// some more fields...
]; ?>
<h2>User settings</h2>
<?php foreach($fields as $fieldName => $field): ?>
<label for="my_user_<?php echo $fieldName; ?>"><?php echo $field['name']; ?></label>
<input type="<?php echo $field['type']; ?>" id="my_user_<?php echo $fieldName; ?>" name="my_user[<?php echo $fieldName; ?>]">
<?php endforeach; ?>
<!-- some more html code... -->
Does anybody know a way so PhpStorm recognizes this correctly? (Beside disabling this check in general)
I already searched for an answer to this question or on how to do it the "correct" way but have not found anything.
Edit: just realised that this only happens on <select> fields and not on normal <input> fields. So in the example code you have to change from input to a select field.
Best regards,
Stefan
Please sign in to leave a comment.
Hello,
What PhpStorm version do you run? I cannot reproduce this in 2018.1.6 and 2018.2 EAP:
Could you run File > Invalidate Caches/Restart > Invalidate and Restart and then check if the issue will reoccur?