【问题标题】:Insert query using ajax drupal使用 ajax drupal 插入查询
【发布时间】:2015-02-23 12:22:36
【问题描述】:

我对 Drupal Ajax 完全陌生。在我的项目中,一个带有提交按钮的简单表单仅用于向数据库插入“是”值。所以应该用 Drupal Ajax 来完成。因此,当该按钮提交时,该值应存储在 Db 中而无需页面加载,并且在提交后显示文本“成功选择”而不是按钮。

所以请任何人都可以帮助我完成这项任务

【问题讨论】:

    标签: ajax database drupal-modules drupal-ajax


    【解决方案1】:

    使用 Drupal Webform Ajax 模块可能会对您有所帮助。

    【讨论】:

      【解决方案2】:

      在这里,我创建了一个无需重新加载页面即可提交的按钮。

      <?php
      
      function db_store_form($form, &$form_state)
      {
          $form['add_button'] = array(
              '#type'  => 'submit',
              '#name'  => 'Yes',
              '#value' => 'Yes',
              '#prefix' => '<div id="wrapper">',
              '#suffix' => '</div>',
              '#ajax' => array(
                  'callback' => 'ajax_yes_callback',
                  'wrapper' => 'wrapper',
                  'method' => 'replace',
                  'effect' => 'fade',
              ),
          );
          return $form;
      }
      
      function db_store_form_submit($form, &$form_state)
      {
          drupal_set_message('Yes has been stored in yes_variable');
          // Store yes in db
          variable_set('yes_variable', 'yes');
      }
      
      function ajax_yes_callback($form, $form_state) {
          return $form['add_button'];
      }
      
      function db_store_menu()
      {
          $items = array();
      
          $items['db_store'] = array(
              'title'           => 'db store',
              'page callback'   => 'drupal_get_form',
              'page arguments'  => array('db_store_form'),
              'access callback' => array(TRUE),
              'type'            => MENU_CALLBACK,
          );
      
          return $items;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-07
        • 1970-01-01
        • 2018-01-22
        • 2018-05-15
        • 1970-01-01
        • 1970-01-01
        • 2021-08-09
        • 2015-01-03
        相关资源
        最近更新 更多