Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用Modal将ID通过Drupal自定义模块传递到表单中_Jquery_Forms_Drupal_Module_Modal Dialog - Fatal编程技术网

Jquery 使用Modal将ID通过Drupal自定义模块传递到表单中

Jquery 使用Modal将ID通过Drupal自定义模块传递到表单中,jquery,forms,drupal,module,modal-dialog,Jquery,Forms,Drupal,Module,Modal Dialog,单击链接时: l(t('Cancel Job'),'clientdash/nojs/form/'.$result->job_id,array('attributes' => array('class' => 'ctools-use-modal'))) 我希望模块能够通过 $items['clientdash/%ctools_js/form/%'] = array( //'title' => 'AJAX modal dialog', 'page callback' =&g

单击链接时:

l(t('Cancel Job'),'clientdash/nojs/form/'.$result->job_id,array('attributes' => array('class' => 'ctools-use-modal')))
我希望模块能够通过

$items['clientdash/%ctools_js/form/%'] = array(
//'title' => 'AJAX modal dialog',
'page callback' => 'clientdash_callback',
'page arguments' => array(1, 3),
//'access callback' => TRUE,
//'type' => MENU_CALLBACK,
);
我继续在表单中出现错误或错误的ID。完整的模块代码如下所示。谢谢,我感谢所有的建议和帮助

<?php

function clientdash_permission() {
return array(
'client permissions' => array(
  'title' => t('Administer permission for your module'),
  'description' => t('Some description that would appear on the permission page..'),
),
);
}


/**
* Implementation of hook_menu().
*/
function clientdash_menu() {
  $items = array();

  $items['clientdash'] = array(
    //'title' => 'Modal test',
    'page callback' => 'clientdash_page',
    'access arguments' => array('client permissions'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['clientdash/%ctools_js/form/%'] = array(
    //'title' => 'AJAX modal dialog',
    'page callback' => 'clientdash_callback',
    'page arguments' => array(1, 3),
    //'access callback' => TRUE,
    //'type' => MENU_CALLBACK,
  );

  return $items;
}

function clientdash_page() {
  //ctools_include('ajax');
  ctools_include('modal');
  ctools_modal_add_js();

  $custom_style = array(
    'clientdash-modal-style' => array(
      'modalSize' => array(
        'type' => 'fixed',
        'width' => 425,
        'height' => 250,
      ),
      'animation' => 'fadeIn',
    ),
  );
  drupal_add_js($custom_style, 'setting');
  $form = array();
  global $user;

  $sql = db_select('job_details', 'jd')->extend('PagerDefault');
   $sql->leftjoin('users', 'u', 'jd.user_id = u.uid');
   $sql->condition('u.uid', $user->uid);
   $sql->condition('jd.jobstatus', 1, "=");
   $sql->fields('jd', array('job_id','title','descr'));
   $sql->orderBy('jd.created_date', 'DESC');
   //$sql->range(0,10);
   $results = $sql->execute();

   $rows = array();

   foreach ($results as $result) {

   $rows[] = array(
             check_markup($result->title),
             check_markup($result->descr),
             l(t('Edit Job'),'editjobform/'.$result->job_id),
             l(t('Responses'),'inquiries/'.$result->job_id),
             l(t('Cancel Job'),'clientdash/nojs/form/'.$result->job_id, array('attributes' => array('class' => 'ctools-use-modal'))),
             //ctools_include('plugins'),
         );
   }
     return theme('table', array('rows' => $rows));
}

/**
* Ajax menu callback.
*/
function clientdash_callback($ajax, $jid = NULL) {
if ($ajax) {
ctools_include('ajax');
ctools_include('modal');

$form_state = array(
'ajax' => TRUE,
'title' => t('Client Dash'),
);

// Use ctools to generate ajax instructions for the browser to create
// a form in a modal popup.
$output = ctools_modal_form_wrapper('clientdash_form', $form_state);

// If the form has been submitted, there may be additional instructions
// such as dismissing the modal popup.
if (!empty($form_state['ajax_commands'])) {
$output = $form_state['ajax_commands'];
}

// Return the ajax instructions to the browser via ajax_render().
print ajax_render($output);
drupal_exit();
}
else {
return drupal_get_form('clientdash_form');
}
}

function clientdash_form($form_state, $jid) {
  global $user;
  $form = array();

  $form['text'] = array(
  '#markup' => '<p><h3><b>To cancel this job, please click Confirm Cancellation!</b></h3></p>'
   );

  //Runs Query to Cancel job
     $query = db_select('job_details', 'jd');
     $query->leftjoin('job_type', 'jt', 'jd.job_type_id = jt.job_type_id');
     $query->fields('jd', array('jobstatus','job_id', 'title', 'descr', 'end_date', 'job_location'));
     $query->fields('jt',array('job_type_id', 'job_type_descr'));
     $query->condition('jd.job_id', $jid, '=');
     //$query->condition('jd.job_id', $result->job_id, '=');
     $query->condition('jd.user_id', $user->uid, '=');
        //$job_id => $form_state['values']['job_id'],
        //'title' => $form_state['values']['title'],
        //'descr' => $form_state['values']['descr']));
    $rslts = $query->execute()->fetchAll();

    //$count = $results->count;


 foreach ($rslts as $rslt) {

     //t('Click Confirm Cancelation to Cancel the Job!');

  $form['job_id'] = array(
    //'#type' => 'hidden',
    '#type' => 'textfield',
    //'#options' => $options,
    '#title' => t('Job ID'),
    '#size' => 15,
    //'#default_value' => $rslt->job_id,
    '#default_value' => $rslt->job_id,
    //'#ajax' => array(
      //'wrapper' => 'updateform',
      //'callback' => 'dbtng_example_form_update_callback',
    //),
  );

  //$form['jobstatus'] = array(
    //'#type' => 'hidden',
    //'#type' => 'textfield',
    //'#options' => $options,
    //'#title' => t('Job status'),
    //'#size' => 15,
    //'#default_value' => $result->jobstatus,
    //'#ajax' => array(
      //'wrapper' => 'updateform',
      //'callback' => 'dbtng_example_form_update_callback',
    //),
 // );



  $form['submit'] = array(
    '#title' => t('Click Cancel Button to Cancel Job!'),
    '#type' => 'submit',
    '#value' => t('Confirm Cancellation'),
  );  

  $form['return'] = array(
  '#markup' => '<p><a href="./?q=clientdash">Return</a></p>'
   );

}

  return $form;
}

function clientdash_form_submit(&$form, &$form_state) {
  $form_state['message'] = t('Message: %message', array('%message' => $form_state['values']['text']));
}

您需要在回调函数中将$jid变量传递到$form\u状态,以便可以在form builder函数中访问它。

好的,在您的帮助下解决它。非常感谢

在代码中对更改进行注释。“//**”表示更改(不带引号)

新代码如下:

<?php

function clientdash_permission() {
  return array(
    'client permissions' => array(
      'title' => t('Administer permission for your module'),
      'description' => t('Some description that would appear on the permission page..'),
    ),
  );
}

/**
* Implementation of hook_menu().
*/
function clientdash_menu() {
  $items = array();

  $items['clientdash'] = array(
    //'title' => 'Modal test',
    'page callback' => 'clientdash_page',
    'access arguments' => array('client permissions'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['clientdash/%ctools_js/%'] = array( //**removed the "form" part of the path
    //'title' => 'AJAX modal dialog',
    'page callback' => 'clientdash_callback',
    'page arguments' => array(1, 2), //**with removing "form" the position needed to updated
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function clientdash_page() {
  //ctools_include('ajax');
  ctools_include('modal');
  ctools_modal_add_js();

  $custom_style = array(
    'clientdash-modal-style' => array(
      'modalSize' => array(
        'type' => 'fixed',
        'width' => 425,
        'height' => 250,
      ),
      'animation' => 'fadeIn',
    ),
  );
  drupal_add_js($custom_style, 'setting');
  $form = array();
  global $user;

  $sql = db_select('job_details', 'jd')->extend('PagerDefault');
   $sql->leftjoin('users', 'u', 'jd.user_id = u.uid');
   $sql->condition('u.uid', $user->uid);
   $sql->condition('jd.jobstatus', 1, "=");
   $sql->fields('jd', array('job_id','title','descr'));
   $sql->orderBy('jd.created_date', 'DESC');
   //$sql->range(0,10);
   $results = $sql->execute();

   $rows = array();

   foreach ($results as $result) {

   $rows[] = array(
             check_markup($result->title),
             check_markup($result->descr),
             l(t('Edit Job'),'editjobform/'.$result->job_id),
             l(t('Responses'),'inquiries/'.$result->job_id),
             l(t('Cancel Job'),'clientdash/nojs/'.$result->job_id, array('attributes' => array('class' => 'ctools-use-modal'))), //**removed "form"
             //ctools_include('plugins'),
         );
   }
     return theme('table', array('rows' => $rows));
}

/**
* Ajax menu callback.
*/
function clientdash_callback($ajax, $jid) { //**made sure $jid was included
if ($ajax) {
ctools_include('ajax');
ctools_include('modal');

$form_state = array(
'ajax' => TRUE,
'title' => t('Client Dash'),
);

$form_state['build_info']['args'] = array($jid); //**added the $form_state as pete80 suggested

// Use ctools to generate ajax instructions for the browser to create
// a form in a modal popup.
$output = ctools_modal_form_wrapper('clientdash_form', $form_state);

// If the form has been submitted, there may be additional instructions
// such as dismissing the modal popup.
if (!empty($form_state['ajax_commands'])) {
$output = $form_state['ajax_commands'];
}

// Return the ajax instructions to the browser via ajax_render().
print ajax_render($output);
drupal_exit();
}
else {
return drupal_get_form('clientdash_form');
}
}

function clientdash_form($form, &$form_state) {
  $jid = $form_state['build_info']['args'][0]; //**added as pete80 suggested
  global $user;
  $form = array();

  $form['text'] = array(
  '#markup' => '<p><h3><b>To cancel this job, please click Confirm Cancellation!</b></h3></p>'
   );

  //Runs Query to Cancel job
     $query = db_select('job_details', 'jd');
     $query->leftjoin('job_type', 'jt', 'jd.job_type_id = jt.job_type_id');
     $query->fields('jd', array('jobstatus','job_id', 'title', 'descr', 'end_date', 'job_location'));
     $query->fields('jt',array('job_type_id', 'job_type_descr'));
     $query->condition('jd.job_id', $jid, '=');
     //$query->condition('jd.job_id', $result->job_id, '=');
     $query->condition('jd.user_id', $user->uid, '=');
        //$job_id => $form_state['values']['job_id'],
        //'title' => $form_state['values']['title'],
        //'descr' => $form_state['values']['descr']));
    //$rslts = $query->execute()->fetchAll();
     $rslts = $query->execute();

    //$count = $results->count;


 foreach ($rslts as $rslt) {

     //t('Click Confirm Cancelation to Cancel the Job!');

  $form['job_id'] = array(
    //'#type' => 'hidden',
    '#type' => 'textfield',
    //'#options' => $options,
    '#title' => t('Job ID'),
    '#size' => 15,
    //'#default_value' => $rslt->job_id,
    '#default_value' => $rslt->job_id,
    //'#ajax' => array(
      //'wrapper' => 'updateform',
      //'callback' => 'dbtng_example_form_update_callback',
    //),
  );

  //$form['jobstatus'] = array(
    //'#type' => 'hidden',
    //'#type' => 'textfield',
    //'#options' => $options,
    //'#title' => t('Job status'),
    //'#size' => 15,
    //'#default_value' => $result->jobstatus,
    //'#ajax' => array(
      //'wrapper' => 'updateform',
      //'callback' => 'dbtng_example_form_update_callback',
    //),
 // );



  $form['submit'] = array(
    '#title' => t('Click Cancel Button to Cancel Job!'),
    '#type' => 'submit',
    '#value' => t('Confirm Cancellation'),
  );  

  $form['return'] = array(
  '#markup' => '<p><a href="./?q=clientdash">Return</a></p>'
   );

}

  return $form;
}

function clientdash_form_submit(&$form, &$form_state) {
  $form_state['message'] = t('Message: %message', array('%message' => $form_state['values']['text']));
}

好吧,我明白你的意思,但我想我不知道如何格式化它。对不起,我还没有尝试过这个。我感谢你的帮助!