I am loading database values in my FORM and seems form is CACHING and loading old data from the database.
I have followed instruction here (How do I prevent a form from being cached for Anonymous users in D8?) but still old data is loaded in form fields.
Here is my code and would appreciate if anyone can shed light where I am missing;
....
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Define form fields.
$form['#cache']['max-age'] = 0;
$form['name'] = array(
'#type' => 'textfield',
'#size' => 80,
'#title' => t('Your Name'),
'#default_value' => $result->name,
);
return $form;
}
....
Do I have to add 'use Drupal\Core\Cache;' on top of this file?
Thanks a lot.