controllo checkbox
Buonasera,
come faccio nel metodo submitForm di una form a controllare se una checkbox è attiva o meno?
Questo è il mio codice dichiarazione checkbox
$options = array();
$options[1] = 'Stato utente';
$form['filters']['stato'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#title' => $this->t('Stato utente'),
);
e metodo di convalida
public function submitForm(array &$form, FormStateInterface $form_state) {
$field = $form_state->getValues();
$nome = $field["nome"];
$cognome = $field["cognome"];
$attivo=$form_state->getValue('stato');
/*
if( !isset($valore) )
$attivo = "0";
else
$attivo = "1";
*/
//$value = array_filter($attivo);
$value = array_filter($ttivo);
var_dump($attivo);
drupal_set_message("Attivo ".$attivo);
$url = \Drupal\Core\Url::fromRoute('gestioneutenti.mostra_utenti')
->setRouteParameters(array('nome'=>$nome,'cognome'=>$cognome,'stato'=>$attivo));
$form_state->setRedirectUrl($url);
}
Risposte
Prova $form_state->getValue([
Prova
$form_state->getValue(['filters', 'stato']);
oppure
$values = $form_state->getValues();
drupal_set_message($values['filters']['stato']);
Risolto grazie
Risolto grazie