【问题标题】:Drupal: full cycle form with parameters and response pageDrupal:带有参数和响应页面的完整循环表单
【发布时间】:2010-07-05 12:16:00
【问题描述】:

我正在尝试制作带有参数和响应页面的完整循环表单。表单工作正常,但响应页面显示为黑色。任何人都有建议或模型示例。

function module99_menu(){
  $items = array();

    // inital form
    $items['module-99'] = array(
        'title'            => t('Export'),       // Page title
        'page callback'    => 'fn_module99',       // function to call when this page is called
        'access arguments' => array('access content'),  // An array of arguments to pass to the access callback function. 
        'description' => t('Export'),
        'type' => MENU_CALLBACK,
    );


    // response page
    $items['my_module-99-response/%/%'] = array(

        'title'            => t('Response Page'),           // Page title
        'page callback'    => 'fn_module99_response',       // function to call when this page is called
        'page arguments'   => array(0,1),                   // pass with arg(0) and arg(1) 
        'access arguments' => array('access content'),      
        'description'      => t('Export - response form'),
        'access callback'  => TRUE,
        'type'             => MENU_CALLBACK,
    );

function fn_module99() {
  return drupal_get_form('module99_my_form');
}


function module99_my_form_validate($form, &$form_state) {
  // do some validation 
}


function module99_my_form_submit($form, &$form_state) {
    // do some stuff
    drupal_set_message(t('The form has been submitted.'));  
    $parms = "p1="  .  "A" . "&p2=" . "B" ;
    $form_state['redirect'] = array('my_module-99-response', $parms);
}

function fn_module99_response($parm1,$parm2) { 
    $output =  $parm1 . $parm2;
    return $output;
}


function module99_my_form($form_state){

    $form = array();

     $form['email'] = array( 
         '#type' => 'textfield', 
         '#title' => t('E-mail address') ,
         '#size' => 64, 
         '#maxlength' => 64, 
         '#required' => TRUE, 
     ); 

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

    return $form;
}

【问题讨论】:

    标签: validation drupal forms parameters


    【解决方案1】:

    你应该稍微改变一下重定向:

    $form_state['redirect'] = array("my_module-99-response/$param_a/$param_b");
    

    您还想在hook_menu 中更改页面参数:

    $items['my_module-99-response/%/%'] = array(
        'page arguments'   => array(1,2),
    );
    

    这将匹配您网址中的两个 %,因为 0 是 'my_module-99-response'

    【讨论】:

      【解决方案2】:

      不知道会不会有帮助,但是标准的方法是使用钩子菜单上的drupal_get_form,将表单的表单id作为参数。我不确定您要对这些参数做什么?

      $items['my_module-99-response/'] = array(
      
          'title'            => t('Response Page'),           // Page title
          'page callback'    => 'drupal_get_form',      
          'page arguments'   => array('fn_module99_response'),     
          'access arguments' => array('access content'),      
          'description'      => t('Export - response form'),
          'access callback'  => TRUE,
          'type'             => MENU_CALLBACK,
      );
      

      您还应该使用“#submit”属性在表单中指定一个提交处理程序(确保传递一个数组)。在进行验证时以相同的方式进行验证。

      function module99_my_form($form_state){
      
      $form = array();
      
       $form['email'] = array( 
           '#type' => 'textfield', 
           '#title' => t('E-mail address') ,
           '#size' => 64, 
           '#maxlength' => 64, 
           '#required' => TRUE, 
       ); 
      
      $form['submit'] = array( 
           '#type' => 'submit', 
           '#value' => t('Save'), 
       );
      $form['#submit'] = array('module99_my_form_submit') ;
      $form['#validate'] = array('module99_my_form_validate') ;
      
      return $form;
      }
      

      【讨论】:

        【解决方案3】:
        $form_state['redirect'] = array("my_module-99-response/$param_a/$param_b");
        

        这很好用,除了 drupal 用编码破坏斜线

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-08-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-29
          • 2018-10-16
          相关资源
          最近更新 更多