$ form ['# validate'] не вызывается - PullRequest
0 голосов
/ 29 января 2020

Все,

Я использую модальное всплывающее окно с javascript в drupal. Поэтому, когда я нажимаю на кнопку отправки, я вижу модальное всплывающее окно, но не проверку. Я могу увидеть подтверждение после нажатия кнопки да / нет в модальном всплывающем окне. Я хотел бы отобразить подтверждение перед отображением модального всплывающего окна.

$form['actions']['modify'] = array(
    '#type' => 'submit',
    '#name' => 'btnModify',
    '#value' => 'Modify to PIS',
    '#id' => 'modalBtn',
    '#executes_submit_callback' => TRUE,
    '#limit_validation_errors' => FALSE,
    //'#process' => array('sdbpisreview_form_validate'),
    '#attributes' => array(
      'class' => 'themed-button orange-button',
    //   'onclick' => 'sdbpisreview_form_validate',
    ),
  );

  $form['actions']['Yes'] = array(
    '#type' => 'submit',
    '#name' => 'btnYes',
    '#value' => 'yes',
    '#id' => 'btnYes',
    '#prefix' => '<html>
      <head>
      <title>Simple Modal</title>
      </head>
      <body>

      <div id="simpleModal" class="modal">
        <div class="modal-content">
          <div class="modal-header">
          <span id="closeBtn" onclick =javascript:close_window(); style="float:right; border:none; display: inline-block;padding: 8px 16px; vertical-align: middle;overflow: hidden;
  text-decoration: none;
  color: inherit;
  background-color: inherit;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  ">&times;</span>
            <h2>Different values of Scheduling and Inventory Database</h2>
          </div>
          <div class="modal-body">
          <table><tr>
     <th style="border:1px solid black; width:30%;">Column Name</th>
     <th style="border:1px solid black; width:40%;"> Scheduling Database </th>
    <th style="border:1px solid black; width:30%;"> Inventory Database </th>
      </tr><tr>
      <td style="border:1px solid black; width:30%; padding:15px;"><p style="white-space: nowrap; overflow: hidden; text-overflow:ellipsis;" id="demo2"></p></td>
      <td style="border:1px solid black; width:40%; padding:15px;"><p style="white-space: nowrap; overflow: hidden; text-overflow:ellipsis;" id="demo"></p></td>
      <td style="border:1px solid black; width:30%; padding:15px;"><p style="white-space: nowrap; overflow: hidden; text-overflow:ellipsis;" id="demo1"></p></td></tr></table>

          </div>
          <div class="modal-footer">'
  );


  $form['actions']['No'] = array(
    '#type' => 'submit',
    '#name' => 'btnNo',
    '#value' => 'No',
    '#id' => 'btnNo',
    '#attributes' => array(
      'onclick' => 'javascript:close_window();',
    ),
    '#suffix' => '<p id = "msg"></p>
                </div>
                <script src = "js/popup.js"></script>
                </div>
                </div></body></html>',
  );

 $form['#validate'] = array('sdbpisreview_form_validate');
 $form['#submit'] = array('sdbpisreview_form_submit');

function sdbpisreview_form_validate($form, &$form_state) {
  drupal_set_message("Validate function");
// We should use the name of the clicked button instead of the id since the
// id is difficult to identify without looking at the page source, can 
// change if the button's location in the form changes, and can also change
// when the form is updated through AHAH callbacks.
//
// The #name property will remain constant.
  $clicked = $form_state['clicked_button']['#name'];
  $values = $form_state['values'];
  dpm($form);




// If the cancel button was pressed, jump back to the experiment page.
  if ('btnCancel' == $clicked) {
// These lines suppress any validation errors that might occur before
// redirecting to the experiment page.
    drupal_get_messages('error');
    form_set_error(NULL, '', TRUE);
    drupal_goto("sdb/expt/{$values['eid_val']}");
    return;
  }

  if (strlen($values['ExExCode']) > 8) {
    form_set_error('ExExCode', 'Experiment code must be <= 8 characters.');
  }
  if (strlen($values['ExName']) > 60) {
    form_set_error('ExName', 'Experiment Name must be <= 60 characters.');
  }
  if (strlen($values['ExDesc']) > 80) {
    form_set_error('ExDesc', 'Experiment Descriptionmust be <= 80 characters.');
  }
  if (strlen($values['ExSponsor']) > 18) {
    form_set_error('ExSponsor', 'Sponsor name must not exceed 18 characters.');
  }
  if ((strlen($values['ExPI']) > 85) || (empty($values['ExPI']))) {
    form_set_error('ExPI', 'Professional Investigator\'s name and organization must not be either exceed 85 characters or empty');
  }
  if (strlen($values['types_Sensor']) > 25) {
    form_set_error('types_Sensor', 'Sensor name must not exceed 25 characters');
  }
  if (strlen($values['types_Recorder']) > 25) {
    form_set_error('types_Recorder', 'Recorder name must not exceed 25 characters');
  }
  if (strlen($values['types_other']) > 50) {
    form_set_error('types_other', 'Other instrument name must not exceed 50 characters');
  }
  if (strlen($values['location']) > 30) {
    form_set_error('location', 'Location name must not exceed 30  characters');
  }
  if (strlen($values['Computer']) > 25) {
    form_set_error('Computer', 'Computer name must not exceed 25 characters');
  }
  if (strlen($values['Power']) > 25) {
    form_set_error('Power', 'Power must not exceed 25 characters');
  }
  if (strlen($values['Notify']) > 30) {
    form_set_error('Notify', 'Notify must not exceed 25 characters');
  }
  if (strlen($values['Personnel']) > 2) {
    form_set_error('Personnel', 'Personnel must not exceed 2 characters');
  }
  if (strlen($values['ExDSGoat']) > 15) {
    form_set_error('ExDSGoat', 'Designated person must be <=15 character long');
  }
  if ($values['ExDF'] == '') {
    form_set_error('ExDF', 'Foreign field must contain "Y" or "N"');
  }
  $form['#attached']['js'] = array(
    drupal_get_path('module', 'sdbpisreview') . '/js/popup.js',
  );
}

Любая помощь будет оценена.

Спасибо

...