Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. /**
  2. * Created by PhpStorm.
  3. * User: sony
  4. * Date: 28/02/2016
  5. * Time: 23:23
  6. */
  7.  
  8. /**
  9. * @file
  10. * Contains Drupalcontact_formFormContributeForm.
  11. */
  12.  
  13. namespace Drupalcontact_formForm;
  14. use DrupalCoreFormFormBase;
  15. use DrupalCoreFormFormStateInterface;
  16. use DrupalComponentUtilityUrlHelper;
  17.  
  18. /**
  19. * Contribute form.
  20. */
  21. class ContributeForm extends FormBase {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function getFormId() {
  26. return 'contact_form_contribute_form';
  27. }
  28.  
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function buildForm(array $form, FormStateInterface $form_state) {
  33. $form['Full Name'] = array(
  34. '#type' => 'textfield',
  35. '#title' => t('Full Name'),
  36. '#required' => TRUE,
  37. );
  38. $form['E-mail'] = array(
  39. '#type' => 'email',
  40. '#title' => t('E-mail'),
  41. );
  42.  
  43. $form['Type of feedback'] = array(
  44. '#type' => 'radios',
  45. '#title' => t('Feedback'),
  46. '#description' => t('Type of feedback'),
  47. '#options' => array(
  48. t('Comments or suggestions'),
  49. t('Questions'),
  50. t('Report a problem(s)'),
  51. t('Other'),
  52. )
  53. );
  54. $form['Subject'] = array(
  55. '#type' => 'textfield',
  56. '#title' => t('Subject'),
  57. );
  58. $form['Your Message'] = array(
  59. '#type' => 'textarea',
  60. '#title' => t('Your Message'),
  61. );
  62. $form['my_captcha_element'] = array(
  63. '#type' => 'captcha',
  64. '#captcha_type' => 'Image',
  65. );
  66.  
  67. $form['sendt'] = array(
  68. '#type' => 'submit',
  69. '#value' => t('Send'),
  70. );
  71. return $form;
  72.  
  73. }
  74.  
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function validateForm(array &$form, FormStateInterface $form_state) {
  79. if (!UrlHelper::isValid($form_state->getValue('video'), TRUE)) {
  80. $form_state->setErrorByName('video', $this->t("The video url '%url' is invalid.", array('%url' => $form_state->getValue('video'))));
  81. }
  82. }
  83.  
  84. /**
  85. * {@inheritdoc}
  86. */
  87. public function submitForm(array &$form, FormStateInterface $form_state) {
  88. foreach ($form_state->getValues() as $key => $value) {
  89. drupal_set_message($key . ': ' . $value);
  90. }
  91. }
  92.  
  93. $form['tabs']['upload']['captcha'] = [
  94. '#type' => 'captcha',
  95. '#captcha_type' => 'captcha/Math',
  96. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement