└── resume ├── resume.module ├── resume.info.yml ├── resume.routing.yml ├── resume.links.task.yml └── src └── Form ├── WorkForm.php └── ResumeForm.php /resume/resume.module: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /resume/resume.info.yml: -------------------------------------------------------------------------------- 1 | name: Resume 2 | description: A Resume form to enter user details. 3 | core: 8.x 4 | package: Custom 5 | type: module 6 | -------------------------------------------------------------------------------- /resume/resume.routing.yml: -------------------------------------------------------------------------------- 1 | resume.form: 2 | path: '/resume/myform' 3 | defaults: 4 | _title: 'Application form' 5 | _form: '\Drupal\resume\Form\ResumeForm' 6 | requirements: 7 | _permission: 'access content' 8 | 9 | work.form: 10 | path: 'resume/mypage' 11 | defaults: 12 | _form: '\Drupal\resume\Form\WorkForm' 13 | _title: 'D8 form' 14 | requirements: 15 | _permission: 'access content' -------------------------------------------------------------------------------- /resume/resume.links.task.yml: -------------------------------------------------------------------------------- 1 | # yaml file to define one or more local task(s). 2 | # 3 | # Definitions can contain any of the following: 4 | # title: (required) The untranslated title of the menu link. 5 | # description: The untranslated description of the link. 6 | # route_name: (optional) The route name to be used to build the path. Either a 7 | # route_name or a link_path must be provided. 8 | # base_route: Used to group together related tabs. 9 | # parent_id: Use the parent_id to relate a tab to a parent tab for multiple 10 | # levels of tabs. 11 | # route_parameters: (optional) The route parameters to build the path. An array. 12 | # link_path: (optional) If you have an external link use link_path instead of 13 | # providing a route_name. 14 | # weight: (optional) An integer that determines the relative position of items 15 | # in the menu; higher-weighted items sink. Defaults to 0. 16 | # Menu items with the same weight are ordered alphabetically. 17 | # options: (optional) An array of options to be passed to l() when generating 18 | # a link from this menu item. 19 | 20 | resume.tab_1: 21 | route_name : resume.form 22 | title: Resume 23 | base_route: resume.form 24 | weight: 10 25 | 26 | resume.tab_2: 27 | route_name: work.form 28 | title: Work 29 | base_route: resume.form 30 | weight: 20 31 | -------------------------------------------------------------------------------- /resume/src/Form/WorkForm.php: -------------------------------------------------------------------------------- 1 | 'textfield', 26 | '#title' => t('Employee Name:'), 27 | '#required' => TRUE, 28 | ); 29 | 30 | $form['employee_mail'] = array( 31 | '#type' => 'email', 32 | '#title' => t('Email ID:'), 33 | '#required' => TRUE, 34 | ); 35 | 36 | $form['actions']['#type'] = 'actions'; 37 | $form['actions']['submit'] = array( 38 | '#type' => 'submit', 39 | '#value' => $this->t('Register'), 40 | '#button_type' => 'primary', 41 | ); 42 | return $form; 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function submitForm(array &$form, FormStateInterface $form_state) { 49 | 50 | drupal_set_message($this->t('@emp_name ,Your application is being submitted!', array('@emp_name' => $form_state->getValue('employee_name')))); 51 | 52 | } 53 | } -------------------------------------------------------------------------------- /resume/src/Form/ResumeForm.php: -------------------------------------------------------------------------------- 1 | 'textfield', 26 | '#title' => t('Candidate Name:'), 27 | '#required' => TRUE, 28 | ); 29 | 30 | $form['candidate_mail'] = array( 31 | '#type' => 'email', 32 | '#title' => t('Email ID:'), 33 | '#required' => TRUE, 34 | ); 35 | 36 | $form['candidate_number'] = array ( 37 | '#type' => 'tel', 38 | '#title' => t('Mobile no'), 39 | ); 40 | 41 | $form['candidate_dob'] = array ( 42 | '#type' => 'date', 43 | '#title' => t('DOB'), 44 | '#required' => TRUE, 45 | ); 46 | 47 | $form['candidate_gender'] = array ( 48 | '#type' => 'select', 49 | '#title' => ('Gender'), 50 | '#options' => array( 51 | 'Female' => t('Female'), 52 | 'male' => t('Male'), 53 | ), 54 | ); 55 | 56 | $form['candidate_confirmation'] = array ( 57 | '#type' => 'radios', 58 | '#title' => ('Are you above 18 years old?'), 59 | '#options' => array( 60 | 'Yes' =>t('Yes'), 61 | 'No' =>t('No') 62 | ), 63 | ); 64 | 65 | $form['candidate_copy'] = array( 66 | '#type' => 'checkbox', 67 | '#title' => t('Send me a copy of the application.'), 68 | ); 69 | 70 | $form['actions']['#type'] = 'actions'; 71 | $form['actions']['submit'] = array( 72 | '#type' => 'submit', 73 | '#value' => $this->t('Save'), 74 | '#button_type' => 'primary', 75 | ); 76 | return $form; 77 | } 78 | 79 | /** 80 | * {@inheritdoc} 81 | */ 82 | public function validateForm(array &$form, FormStateInterface $form_state) { 83 | 84 | if (strlen($form_state->getValue('candidate_number')) < 10) { 85 | $form_state->setErrorByName('candidate_number', $this->t('Mobile number is too short.')); 86 | } 87 | 88 | } 89 | 90 | /** 91 | * {@inheritdoc} 92 | */ 93 | public function submitForm(array &$form, FormStateInterface $form_state) { 94 | 95 | // drupal_set_message($this->t('@can_name ,Your application is being submitted!', array('@can_name' => $form_state->getValue('candidate_name')))); 96 | 97 | foreach ($form_state->getValues() as $key => $value) { 98 | drupal_set_message($key . ': ' . $value); 99 | } 100 | 101 | } 102 | } --------------------------------------------------------------------------------