繁体   English   中英

创建自定义表单在drupal 7的每个页面的colorbox中显示它吗?

[英]Create custom form display it in colorbox in each page in drupal 7?

我想在每个页面的颜色框中显示自定义表单(这是自定义模块)。

我已经在drupal 7中创建了表单,如果我通过在url中调用它来运行它,则可以正常工作,但是我需要在colorbox中调用此模块。

我的自定义模块(regform)代码是

  function regform_init() {
    drupal_set_message('Our module is alive!');
  }
  function regform_menu() {
    $items = array();
    $items['regform'] = array(
      'title' => 'Custom page',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('regform_form'), 
      'access arguments' => array('access content'),
      'access callback' => TRUE
    );
    return $items;
  }
  function regform_form($form, &$form_state) {
    $form['#suffix'] = '<div id="test-ajax"></div>';
     $form['email'] = array(
      '#type' => 'textfield', //you can find a list of available types in the form api
      '#title' => 'Enter Email',
      '#size' => 50,
      '#maxlength' => 50,
      '#required' => TRUE, //make this field required
    );
    $form['submit_button'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
      '#validate' => 'regform_form_validate',
      '#ajax' => array(
        'callback' => 'regform_form_ajax_callback',
        'wrapper' => 'test-ajax'
      ),
      '#submit' => array('regform_form_ajax_callback'),
    );
    return $form;
  }
  function regform_form_ajax_callback($form, &$form_state) { 
    /*Fire database query*/
    /*Validation msg div block call here*/
    return "<div id='test-ajax'></div>";
  }
  function regform_form_validate($form, &$form_state) {
    if (trim($form_state['values']['email']) == ''){
      form_set_error('email', t('Please Enter Email'));
    }
    if(!valid_email_address($form_state['values']['email'])){
      form_set_error('email', t('Enter Valid Email'));
    }
  }
  function regform_form_submit($form, &$form_state) {
      $form_state['rebuild'] = TRUE;
      $form_state['input'] = array();
  }

此表格工作正常。

我也不知道如何在drupal 7中使用colorbox。

任何帮助将不胜感激。

提前致谢。

我建议对模式弹出窗口使用混乱的工具 它易于实现并集成到Drupal 7中。

这里给出了Ctools模态形式的一个很好的例子

对于Drupal中的模态形式,我强烈建议您看一下混乱的工具 它提供了一个出色的AJAX API(可以处理表单提交)。

您可以查看模态形式的另一个模块。 它建立在Ctools之上,并提供了一种简单的方式来显示形式的形式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM