I am grabbing data dynamically in PHP and placing it in the name
attribute of the input type="text"
. And based on a condition on the returned data, type="checkbox"
element is given a checked
attribute. They display as intended on the first page load.
But even if I 'casually' enter a value in these input fields or change the checkbox status and refresh the page, without submitting the form, these values are saved in the browser somehow and they are displayed rather than the dynamically grabbed data. To tackle this I turned the autocomplete
attribute on
for text. Works well, but now the problem is that the dynamic data too is not populated. It leaves the input fields blank.
And also for the checkbox
field, even though I have the checked
attribute turned on based on a condition on grabbing data from backend, if I uncheck it and refresh page (without submitting the form) it remains unchecked. They work well on a hard-refresh. What could be the issue? Thank you.
<div class="timing">
<?php
foreach ($value as $ky => $val) : ?>
<?php
if( strstr( $ky, 'AM' ) ) : ?>
<input name="<?php echo $ky; ?>" type="number" value="<?php echo $val; ?>" class="am" placeholder="am"/>
<?php
elseif( strstr( $ky, 'PM' ) ) :?>
<input name="<?php echo $ky; ?>" type="number" value="<?php echo $val; ?>" class="pm" placeholder="pm"/>
<?php endif; endforeach; ?>
</div>
<?php
foreach ($value as $ky => $val) :
if( strstr( $ky, 'Closed' ) && !empty($val) ) :?>
<input name="<?php echo $ky; ?>" type="checkbox" class="closed_active closed" checked/>
<?php
elseif( strstr( $ky, 'Closed' ) ) : ?>
<input name="<?php echo $ky; ?>" type="checkbox" class="closed"/>
<?php endif; endforeach; ?>