Getting the original form with error message in drupal ajax call back I have a drupal form which accept email id and ajax call is implemented for the submit button.In addition to submit call back.The return values are collected in the wrapper and my requirement is to display the form along with an error message if the email is not valid.

I tried to return the form along with message to the wrapper from submit,but the ajax call was not happening.

Also i tried to reset the form_state array empty in the submit call back, but execution stopped at that point.

Am i on the correct track?
Please help me in solving this.Sorry for my english.
For Drupal 7 you can use the below code


    /**
     * Implements hook_menu().
     */
    function hook_menu() {
        $items['test_ajax'] = array(
            'title' => 'test ajax',
            'page callback' => 'drupal_get_form',
            'page arguments' => array('demo_form'),
            'access callback' => TRUE,
            'type' => MENU_CALLBACK,
        );
            ....
    }   

    /**
     * Implements hook_form().
     */
    function demo_form($form, &$form_state) {
        return array(
            'email' => array(
                '#type' => 'textfield',
                '#title' => t("Join our Newsletter"),
                '#required' => TRUE,
                '#attributes' => array(
                    'placeholder' => t("mail@example.com")
                ),
            ),
            'submit' => array(
                '#type' => 'submit',
                '#value' => t('Subscribe'),
                '#ajax' => array(
                    'callback' => 'demo_form_ajax_submit',
                    'wrapper' => 'demo-form',
                    'method' => 'replace',
                    'effect' => 'fade',
                ),              
            ),
        );
    }

    /**
     * Ajax callback function.
     */
    function demo_form_ajax_submit($form, $form_state) {
        drupal_set_message();
        $message = '';
        if (!empty($form_state['input']['email'])) {
            if (valid_email_address($form_state['input']['email'])) {
                $message = "subscription successful!!!";
                $status = 'status';
            }
            else {
                $message = 'Please enter valid email ID!!';
                $status = 'error';
            }
            drupal_set_message($message, $status);
        }
        $form_state['rebuild'] = TRUE;
        return $form;
    }