Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • how to set a custom message using form_alter in Drupal

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.40k
    Comment on it

    At times we need to change the message that is displayed after a node is saved.Follwing code helps to customize using form_alter.

    function mymodule_form_alter(&$form, &$form_state, $form_id) 
    {
        if($form['form_id']['#value'] =='formvalue')
        {   
              if($form['buttons']['submit']['#submit']){
                $form['buttons']['submit']['#submit'][] = 'mymodule_submit_function';
              }
        }
    }
    
    function mymodule_submit_function($form, &$form_state){
    
        global $_SESSION;
        $insert = empty($form_state['values']['nid']);
        if($insert){
            //Write your custom message text here
            if($form['nid']['#post']['form_id'] == 'formvalue'){
                $keys = array_keys($_SESSION['messages']['status']);
                $last_key = end($keys);
                $message = 'My custom messge after node save';
                $_SESSION['messages']['status'][$last_key] = $message;
            }
        }
    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: