Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By peterk900 on
This code
function demo_demo_form($form, &$form_state) {
return array(
'email' => array(
'#type' => 'textfield',
'#title' => t('Please supply email address'),
'#required' => TRUE,
'#attributes' => array(
'placeholder' => t('mail@mycompany.com'),
),
),
'submit' => array(
'#type' => 'submit',
'#value' => t('Subscribe'),
'#ajax' => array(
'callback' => 'demo_form_ajax_submit',
'wrapper' => 'demo-demo-form',
'method' => 'replace',
'effect' => 'fade',
),
),
);
}
/**
* Ajax callback function.
*/
function demo_form_ajax_submit($form, $form_state) {
// --- Database update TODO
$form_state['rebuild'] = FALSE;
$form_state['values']['email'] = "";
return $form;
}
redisplays the single field input form after submission with the previously entered value. In order to indicate to the user that the record has been saved, I'd like to remove the previous value and perhaps re-display the entry prompt Please supply email address. The code above has no effect. What am I doing wrong ? Thanks.
Comments
You want this:
You want this:
Thanks..
However this code removes the text box, leaving only the submit button.
But looking back at a previous post you helped with I tried:
$form['email']['#value']= "";
and this displays the prompt which the field shows when the form opens, which is ideal.
Oh, that's correct. I was
Oh, that's correct. I was having a stupid moment!
This discussion was helpful,
This discussion was helpful, Thanks !!