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

Jaypan’s picture

You want this:

$form['email'] = "";		
peterk900’s picture

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.

Jaypan’s picture

Oh, that's correct. I was having a stupid moment!

nitin.k’s picture

This discussion was helpful, Thanks !!