I created my form but inserting the base does not work also radios type does not appear in the form
<?php
/**
* @file
* Contains \Drupal\contact_form\Form\ContributeForm.
*/
namespace Drupal\contact_form\Form;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ChangedCommand;
use Drupal\Core\Ajax\CssCommand;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Ajax\InvokeCommand;
/**
* Contribute form.
*/
class ContributeForm extends FormBase implements FormInterface{
protected $accepted_domains = ['gmail.com', 'yahoo.com'];
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'contact_form_contribute_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['FullName'] = array(
'#type' => 'textfield',
'#title' => $this->t('Full Name'),
'#required' => TRUE,
);
$form['Email'] = array(
'#type' => 'email',
'#title' => $this->t('Email address'),
'#required' => true,
'#size' => 60,
'#maxlength' => 128,
);
$form['Feedback'] = array(
'#type' => 'radios',
'#title' => $this->t('Feedback'),
'#description' => t('Type of feedback'),
'#default_value' => 0,
'#options' => array(
0 =>'Comments or suggestions',
1 => 'Questions',
2 =>'Report a problem(s)',
3 =>'Other',
)
);
$form['Subject'] = array(
'#type' => 'textfield',
'#title' => $this->t('Subject'),
'#required' => true,
);
$form['Message'] = array(
'#type' => 'textarea',
'#title' => $this->t('Your Message'),
'#required' => true,
'#cols' => 90,
'#rows' => 10,
);
$form['captcha'] = array(
'#type' => 'captcha',
'#captcha_type' => 'recaptcha/reCAPTCHA',
'#title' => $this->t('Captcha:'),
'#required' => true,
);
$form['save'] = array(
'#type' => 'submit',
'#input' => TRUE,
'#value' => 'save',
'#submit' => array('buildForm')
);
return array(
'#form' => $form,
'#theme' => 'contribute',
);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$name = $form_state->getValue('FullName');
$email = $form_state->getValue('Email');
$subject = $form_state->getValue('Subject');
$type = $form_state->getValue('TypeFeedback');
$msg = $form_state->getValue('Message');
$field = array(
'FullName' => $name,
'Email' => $email,
'TypeFeedback' => $type ,
'Subject' => $subject,
'Message' => $msg,
'Etat_message'=> '',
'Date_contact'=> '',
'adresse_IP'=> '',
);
db_insert('contact')
->fields($field)
->execute();
drupal_set_message("succesfully saved");
}
}