When clicking on the link:
l(t('Cancel Job'),'clientdash/nojs/form/'.$result->job_id,array('attributes' => array('class' => 'ctools-use-modal')))
I want the module to be able to pass an ID through
$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,
);
I continue to get errors or the wrong ID pops into the form. The full module code is below. Thanks and I appreciate all suggestions and help!
<?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_state中,以便可以在表单构建器函数中对其进行访问。
Alright, figured it out but with your help pete80. Thanks so much!
Changes are commented in the code. "//**" indicates a change (without the quotes).
New Code is below:
<?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']));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.