0

I am using Drupal 8.6 for creating custom module in Admin. I have a custom form where i have to use multiple submit button for form submission. I am not able to submit the my form to specific function. Below is my code.

public function buildForm(array $form, FormStateInterface $form_state) {

    $connection = \Drupal::service('database');

        $form_state->setMethod('get');

        $build = [];

        /* $build['form'] = [
        '#type'  => 'get',
    ]; */

    $build['submit_button_1'] = [
              '#type' => 'submit', 
              '#value' => t('Download CSV'),
              '#name' => t('downloadcsv'),
              '#executes_submit_callback'=>FALSE,             
              '#submit' => array('::downloadcsv'),

        ];  
    $build['form']['filters'] = [
        '#type'  => 'fieldset',
        '#title' => $this->t('Filter'),
        '#open'  => true,
    ];


    $build['form']['filters']['autocomplete_field'] = array(
    '#type' => 'textfield',
    '#title'         => 'Search by Name',
    '#autocomplete_route_name' => 'form_request.autocomplete',
    '#autocomplete_route_parameters' => array('field_name' => 'name', 'count' => 10),
    '#default_value' => isset($_GET['autocomplete_field']) ? trim($_GET['autocomplete_field']):'',
);


    $build['form']['filters']['form_name'] = [
        '#title'         => 'Form Name',
        '#type'          => 'select',
        '#empty_value'   => 'none',
        '#empty_option'  => '- None -',
        '#size'          => 0,
        '#options'       => $this->get_formlist(),
        '#default_value' => isset($_GET['form_name']) ? trim($_GET['form_name']):''
    ];

    $build['form']['filters']['request_status'] = [
        '#title'         => 'Request Status',
        '#type'          => 'select',
        '#empty_value'   => 'all',
        '#empty_option'  => '- None -',
        '#size'          => 0,
        '#options'       => array("all"=>"All","inprogress"=>"In progress","pending"=>"Pending","completed"=>"Completed",'rejected' => "Rejected"),
        '#default_value' => isset($_GET['request_status']) ? trim($_GET['request_status']):''
    ];


    $build['form']['filters']['actions']['submit'] = [
        '#type'  => 'submit',
        '#value' => $this->t('Filter')
    ];  
    $build['form']['filters']['actions']['reset'] = [
        '#type'  => 'button',
        '#value' => $this->t('Reset'),
        '#target'=>'_self',
        '#attributes' => array(
            'onclick' => 'redirectURL("'.$resetURL.'")',
            //'onclick' => '$("#form-request").reset()',
          ),
    ];


return $build;

}

 public function downloadcsv(array &$form, FormStateInterface $form_state) {

     echo "aaaaa"; exit;

  }

Your Answer

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

Browse other questions tagged or ask your own question.