• <legend id='h4JSV'><style id='h4JSV'><dir id='h4JSV'><q id='h4JSV'></q></dir></style></legend>

        <bdo id='h4JSV'></bdo><ul id='h4JSV'></ul>
    1. <i id='h4JSV'><tr id='h4JSV'><dt id='h4JSV'><q id='h4JSV'><span id='h4JSV'><b id='h4JSV'><form id='h4JSV'><ins id='h4JSV'></ins><ul id='h4JSV'></ul><sub id='h4JSV'></sub></form><legend id='h4JSV'></legend><bdo id='h4JSV'><pre id='h4JSV'><center id='h4JSV'></center></pre></bdo></b><th id='h4JSV'></th></span></q></dt></tr></i><div id='h4JSV'><tfoot id='h4JSV'></tfoot><dl id='h4JSV'><fieldset id='h4JSV'></fieldset></dl></div>

      1. <small id='h4JSV'></small><noframes id='h4JSV'>

      2. <tfoot id='h4JSV'></tfoot>

        Drupal:如何使用 AJAX POST 从 REST 服务提交 webfrom

        时间:2024-04-19

              <legend id='2Batd'><style id='2Batd'><dir id='2Batd'><q id='2Batd'></q></dir></style></legend><tfoot id='2Batd'></tfoot>
            1. <i id='2Batd'><tr id='2Batd'><dt id='2Batd'><q id='2Batd'><span id='2Batd'><b id='2Batd'><form id='2Batd'><ins id='2Batd'></ins><ul id='2Batd'></ul><sub id='2Batd'></sub></form><legend id='2Batd'></legend><bdo id='2Batd'><pre id='2Batd'><center id='2Batd'></center></pre></bdo></b><th id='2Batd'></th></span></q></dt></tr></i><div id='2Batd'><tfoot id='2Batd'></tfoot><dl id='2Batd'><fieldset id='2Batd'></fieldset></dl></div>
                  <bdo id='2Batd'></bdo><ul id='2Batd'></ul>
                    <tbody id='2Batd'></tbody>
                • <small id='2Batd'></small><noframes id='2Batd'>

                  本文介绍了Drupal:如何使用 AJAX POST 从 REST 服务提交 webfrom的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I am having web form module in drupal. I want to submit a form into webform from external app with REST service using the AJAX POST method. I can able to retrieve the web form (node/1) using ajax. On submitting it should not create as new node, instead it will get add into web form.

                  Thanks in advance for any help.....

                  解决方案

                  To be able to retrieve data from and send data to Webform module with an external application I suggest you to use Webform Service module of Drupal that makes REST API available for your surveys.

                  Once you've installed and configured the modules and its dependencies (if any) you'll be able to retrieve the serialized data of a survey. Also you can send submission by an appropriate request to the endpoint with proper HTTP method (GET, POST etc..). See description of endpoints on the page of Webform Service module.

                  You need to know the format of the data you are going to submit. Hereby you will find the right format of JSON object. The value of the values key is an array either it has one or more values, so most of the time it looks like this:

                  {'values':{0:"put your value here"}}
                  

                  In case of multiple values (checkbox, multi-select) it is possible to use values like this:

                  {'values':{
                      0:"put your value1 here",
                      1: "put your value2 here",
                  }}
                  

                  Finally here is a snippet of HTML and AngularJS to prepare and post a request to the REST API.

                  HTML

                  <form ng-submit="submit('put the UUID of the survey here')" ng-controller="formCtrl">
                    <label>Your name:</label><br/>
                    <input type="text" ng-model="formData[1]['values'][0]" /><br/>
                    <label>I like tea</label><br/>
                    <input type="checkbox" ng-model="formData[2]['values'][0]" value="tea" /><br/>
                    <label>I like coffee</label><br/>
                    <input type="checkbox" ng-model="formData[2]['values'][1]" value="coffee" /><br/>
                    <input type="submit" value="Send" />
                  </form>
                  

                  Note that you don't need to write static HTML form, but you can retrieve the data of the survey from the API and build the form by a script.

                  JavaScript

                  var app = angular.module('webformApp', []);
                  
                  app.config(['$httpProvider', function($httpProvider) {
                          $httpProvider.defaults.useXDomain = true;
                          delete $httpProvider.defaults.headers.common['X-Requested-With'];
                      }
                  ]);
                  
                  app.controller('formCtrl', function($scope, $element, formService) {
                      $scope.submit = function(uuid){
                        formService.postForm(uuid, this);
                      };
                  });
                  
                  app.service('formService', function($http){
                      return {
                          postForm: function(uuid, $scope){
                            var toPost = {
                              webform: uuid,
                              submission: {
                                  data: $scope.formData
                              }
                            };
                            console.log(toPost);
                            console.log(JSON.stringify(toPost));
                            return $http.post('http://example.com/yourendpoint/submission', toPost);
                          }
                      };
                  });
                  

                  To try/test the API itself you can use Postman extension of Chrome browser. This JS will log the JSON string to the console to send it to API.

                  Have fun!

                  这篇关于Drupal:如何使用 AJAX POST 从 REST 服务提交 webfrom的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:jQuery 无法正确渲染 下一篇:在特定内容类型的节点创建上执行 JavaScript

                  相关文章

                • <i id='dyDY7'><tr id='dyDY7'><dt id='dyDY7'><q id='dyDY7'><span id='dyDY7'><b id='dyDY7'><form id='dyDY7'><ins id='dyDY7'></ins><ul id='dyDY7'></ul><sub id='dyDY7'></sub></form><legend id='dyDY7'></legend><bdo id='dyDY7'><pre id='dyDY7'><center id='dyDY7'></center></pre></bdo></b><th id='dyDY7'></th></span></q></dt></tr></i><div id='dyDY7'><tfoot id='dyDY7'></tfoot><dl id='dyDY7'><fieldset id='dyDY7'></fieldset></dl></div>
                  <tfoot id='dyDY7'></tfoot>
                  1. <legend id='dyDY7'><style id='dyDY7'><dir id='dyDY7'><q id='dyDY7'></q></dir></style></legend>

                    <small id='dyDY7'></small><noframes id='dyDY7'>

                    • <bdo id='dyDY7'></bdo><ul id='dyDY7'></ul>