-1

My problem is that when i click the form submit the page reloads but do nothing. whithin the submit function i have a statement where i dump the $form variable. as nothing happens i figured that the process does not reach the submit function at all and it must be stopping at the validation phase.

below you find my form structure (LoginForm).

LoginForm.php

class LoginForm extends FormBase{
/**
* {@inheritdoc}
*/
public function getFormId(){
    return 'login_form';
}

/*
 * {@inheritdoc}
 */

public function buildForm(array $form, FormStateInterface $form_state){
    //$theme_dir = $GLOBALS["base_url"].'/'.drupal_get_path('theme', 'epw');
    $form = array();

    //$form['#attributes']['class'][] = 'login';

    $form['user_email'] = array(
        '#type' => 'email',
        //'#title' => $this->t('E-mail'),
        '#prefix' => '<div  class="db f5 dark-gray text textinp">E-mail</div >',
        '#default_value' => '',
        '#required' => TRUE,
        '#attributes' => array(
            'id' => 'mail',
            'name' => 'mail',
            'class' => array('b', 'pa3', 'input-reset', 'ba', 'bg-transparent', 'hover-bg-moon-gray', 'hover-black', 'w-100'),
        ),
    );

    $form['user_pass'] = array(
        '#type' => 'password',
        //'#title' => $this->t('Mot de passe :'),
        '#prefix' => '<div  class="db f5 dark-gray text textinp textinp2">Mot de passe :</div >',
        '#size' => 8,
        '#required' => TRUE,
        '#attributes' => array(
            'id' => 'password',
            'name' => 'password',
            'class' => array('b', 'pa3', 'input-reset', 'ba', 'bg-transparent', 'hover-bg-moon-gray', 'hover-black', 'w-100'),
        ),
    );

    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('SE CONNECTER'),
        '#button_type' => 'primary',
        '#prefix' => '<div class="tr mpoub">
                        <a href="index_mpoublier.php" class="tr f6 dark-gray ">Mot de passe oublié ? </a>
                      </div>
                      <div class="subhold tc">',
        '#suffix' => '</div>',
        '#attributes' => array(
            'name' => 'checklogin',
            'class' => array('f6', 'ttu', 'link', 'dim', 'ba', 'ph3', 'pv3', 'dib', 'white', 'bg-green', 'btn'),
        ),
    );

    return $form;
}

/**
* {@inheritdoc}
*/
public  function submitForm(array &$form, FormStateInterface $form_state){
    $email_value = $form_state->getValue('user_email');
    $msg = 'Votre email a bien etè envoyè. Vous avez recu une confirmation à ' . $email_value;
    drupal_set_message($msg);
}

/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $formState){}
}

Any ideas on the source of the problem? Am i missing something?

1
  • It's not possible to guess what might be wrong with unseen code. Please produce an MCVE and edit it into the question, so people have a chance of understanding the source of the problem. Once that's done please flag for re-opening. Thanks
    – Clive
    Oct 20, 2017 at 12:36

1 Answer 1

0

So i did found the culprit; and it was the attribute "name". it seems that it ovverides the actual name so when i call $form_state->getValue('user_email'); it does not know what i'm talking about but even with $form_state->getValue('mail'); it does not work (don't know why at the moment). and because i made both field required the validation does not success and therefore it does not reach the submit function. so i just remove the attribute name :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.