1

I am using Drupal 7 and have a custom module where I am creating a menu item which will display a Drupal form. The code is setup like this:

$items['job-seekers/update-resume/%'] = array(
  'title' => 'Update Resume',
  'page callback' => 'drupal_get_form',
  'page arguments' => 'oa_onboard_update_resume_form',    
  'access arguments' => array('access content'),
  'page arguments' => array(2),
);

So my menu item will display a form, but I need to take the parameter passed in the URL and have it stored in a hidden form field that will end up getting passed to the form submission method for processing. My form code looks like this:

/**
 * Form callback for updating resume
 */
function oa_onboard_update_resume_form($form_state) {  

  $form['resume_file'] = array(
    '#type' => 'file',
    '#title' => t('Resume Upload'),
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  return $form;
}

So it's a very simple form that is just a file upload field, however I can't figure out how to gain access to the ID that is passed in the URL. Originally I was thinking I needed to account for it in the form method like so:

function oa_onboard_update_resume_form($candidateId) { 

But I get an error when I try to do that:

Notice: Undefined index: 20249278 in drupal_retrieve_form() (line 763 of C:\xampp\htdocs\mysite\includes\form.inc).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '20249278' not found or invalid function name in drupal_retrieve_form() (line 798 of C:\xampp\htdocs\mysite\includes\form.inc).

I think I might be going about this the wrong way. The bottom line is I just need to create a URL that I can pass an ID to that will display a form and pass that ID to the submit method along with the file upload.

Thanks in advance.

EDIT Here is the new callback function that renders the form after fixing the menu item per the suggestion below:

function oa_onboard_update_resume_form($candidateId) {  

  $form['candidateId'] = array(
    '#type' => 'hidden',
    '#value' => $candidateId,
  );

  $form['resume_file'] = array(
    '#type' => 'file',
    '#title' => t('Resume Upload'),
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  return $form;
}
4

2 回答 2

1

在 hook_menu 函数中,您设置了两次“页面参数”,您应该将“页面回调”与函数一起使用oa_onboard_update_resume_form

$items['job-seekers/update-resume/%'] = array(
  'title' => 'Update Resume',
  'page callback' => 'oa_onboard_update_resume_form',    
  'access arguments' => array('access content'),
  'page arguments' => array(2),
);
于 2013-07-30T14:41:11.733 回答
1

好的,这就是最终的工作:

$items['job-seekers/update-resume/%'] = array(
  'title' => 'Update Resume',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('oa_onboard_update_resume_form', 2),
  'access arguments' => array('access content'),
);

function oa_onboard_update_resume_form($form, &$form_state, $candidateId) {
  // I can use candidateId here now
}
于 2013-07-31T15:39:05.223 回答