Von Version 11.8
bearbeitet von gru
am 02.03.2023, 09:15
Änderungskommentar: Es gibt keinen Kommentar für diese Version
Auf Version 7.1
bearbeitet von MKO
am 05.10.2022, 11:50
Änderungskommentar: Es gibt keinen Kommentar für diese Version

Zusammenfassung

Details

Seiteneigenschaften
Titel
... ... @@ -1,1 +1,1 @@
1 -Formular über externen Kontext einbinden
1 +Formular per AJAX einbinden
Dokument-Autor
... ... @@ -1,1 +1,1 @@
1 -XWiki.gru
1 +XWiki.mko
Inhalt
... ... @@ -1,123 +1,159 @@
1 -== 1. Externen Kontext via iFrame einbinden z.B. ==
1 +{{html clean="false"}} <script type="text/javascript" src="https://demo7.formcycle.eu/formcycle/form/includes/010-jquery-min.js?_nc=1637667410192" ></script>
2 +<script type="text/javascript" src="https://demo7.formcycle.eu/formcycle/form/include.js?form_id=564&form_base=https%3A%2F%2Fdemo7.formcycle.eu%2Fformcycle&auto=1&form_container_id=content" ></script>
2 2  
3 -[[https://pro.form.cloud/formcycle/external/forms/main.xhtml]]
4 +<style type="text/css">
5 + pre{
6 + margin:0;
7 + }
4 4  
5 -TODO: iframe
9 + .xm-form{
10 + margin:0 auto;
11 + }
6 6  
7 -== 2. Eventlistener für Formularauswahl registrieren z.B.: ==
13 + .extra .hljs-string{
14 + font-weight:bold;
15 + color:red;
16 + }
8 8  
18 + iframe, .hljs{
19 + max-width:700px;
20 + border:2px solid #515151;
21 + }
9 9  
23 + .hljs{
24 + max-width:985px;
25 + text-align:center;
26 + }
10 10  
11 -
12 -{{code language="javascript"}}function myFormCycleCallback(msg){
13 - $('#result').html('Nachricht von: "<b>' + msg.origin + '</b>" Formular mit id: "<b>' + msg.data + '</b>" wurde ausgewählt.' );
14 - renderForm(msg.data);
15 -}
28 + span.box{
29 + display: block;
30 + padding: 20px;
31 + }
32 +</style>
16 16  
17 -window.addEventListener("message", myFormCycleCallback, false);{{/code}}
34 +<script>
35 + $.noConflict();
18 18  
37 +window.xima.fc.form.load = (function(options, trigger){
38 +(function($, options, trigger){
19 19  
20 -== 3. Ergebenis speichern: ==
40 + var options = options || {},
41 + o = $.extend({
42 + loadingImageURL : window.xima.fc.form.loadingImageURL || "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAC4jAAAuIwF4pT92AAABymlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iCiAgICAgICAgICAgIHhtbG5zOnRpZmY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vdGlmZi8xLjAvIj4KICAgICAgICAgPHhtcDpDcmVhdG9yVG9vbD5wYWludC5uZXQgNC4wLjU8L3htcDpDcmVhdG9yVG9vbD4KICAgICAgICAgPHRpZmY6T3JpZW50YXRpb24+MTwvdGlmZjpPcmllbnRhdGlvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CqgdUBYAAAKgSURBVCgVbVJbS1RRFP7WPufMGS/TKKJm2EXQAgctRBIywggCSYQCX3oSiyLEqJcIujAPQfUfCowepcKnKCotMCy8lJeHIhALxQujoc4457ZX6zhiEH0Pe5+9z1rr+/a3FvE4DoBwDgqm70fHrIbsm56eVntocnenJt4H5gyIGBqQGDkiAFO+XM0Qf0IJbAyjCtU8Yy1SlVdLcf59/HTnbJZilRy4MExbMgUkyTqAFclDZi01b1ITUvwFN/ATz6kY5ZjDdYm6o7kzxdqp9H1vIfDcCaKQVLgZnudk4sI8nqsoK39FP89ZzFOYX3hX24TyCwOn2ru57kTn252gZFKE/4XiEVhbR42HvAQfBaiIx5avoYjNdReImn+DkUyGL9+BiUb4okeJrI/BuNFL+d5FRfpQ8/7A+JXW2BtlG81dsfoCTyvXsOw8T/ueS1gtzpihBzwIQ8pplyvuRZdnzsqVtbKpPFOE+Iwjh009Ql4YAnY2LZFuRTjuXMqJer/VCOQ1zMzypFgmf1dccmIRsQhUYEaiB4VEIGeRqMiAl82U5JLbhDkpzGOxLsTX62mJhkttjmTJhGL/m+c690khkAI5etbKtHjI5AGY1AhPjC/ScG4iLEfkLDug0sKwMzw/8aH3yRbxP4uJllCLwMBVFeMapADXi75Y/Gy017aJL2tkJBIdkenphF/dmrLiS86W46OjewJTnhAIa42U6EZEihBeHbt78lHZUf+8r21oGY7p6T5pWh9+vITs22TykWu6kqmKoyxklVF9MPH6aTpRrO20q8ORCplyfiG5vcuNQAnrGeTjCnYBga+eUQ0GEy0dhesuFdiRqISQ/Pk/xE5sYgO3kcamr6P9gIPLdRve46nYrSC9WqWU+i6pOV+Q3N5zxf4AusodlJW0va8AAAAASUVORK5CYII=",
43 + loadingImageStyle : window.xima.fc.form.loadingImageStyle || ".xm-form-loader-icon { text-align:center; -webkit-animation: spin 0.5s ease-in-out infinite; -moz-animation: spin 0.5s ease-in-out infinite; animation: spin 0.5s ease-in-out infinite;} @-moz-keyframes spin { 100% { -moz-transform: rotateY(360deg); } }@-webkit-keyframes spin { 100% { -webkit-transform: rotateY(360deg); } }@keyframes spin { 100% { -webkit-transform: rotateY(360deg); transform:rotateY(360deg); } }"
44 + },options);
21 21  
22 -{{html clean="false"}}
23 - <div class="hljs" id="result"></div>
24 -{{/html}}
46 + var d = $.extend({
47 + "xfc-rp-inline":true,
48 + "xfc-rp-form-only":true,
49 + "xfc-pp-external":true,
50 + "xfc-rp-usejq":false,
51 + "xfc-rp-keepalive":false,
52 + "xfc-rp-usecss":true,
53 + "xfc-rp-useui":true,
54 + "xfc-pp-base-url": o.form_base,
55 + "fcpuid":window.xima.fc.form.fcpuid
56 + }, {"auto":"1","form_id":"253","form_container_id":"content"}, o.data);
25 25  
58 + function success(html){
59 + o.form_container.html(html.replace(/\$/g,'jQuery'));
60 + checkIsLogin();
61 + }
26 26  
27 -== 4. Formular einbinden: ==
63 + function error(data){
64 + o.form_container.html(data.responseText);
65 + checkIsLogin();
66 + }
28 28  
29 -{{code language="js"}}
30 -window.renderForm = function(formId){
31 - var myBase = 'https://help6.formcycle.eu/xwiki/bin/edit/Examples/IncludeFormViaExternalContext/';
32 - var fcBase = 'https://pro.formcloud.de/formcycle';
33 - var myFormContainer = $('#content');
34 -
35 - var form = $.ajax({
36 - type: "GET",
37 - url: fcBase + '/form/provide/' + formId,
38 - data:{
39 - //Render-Parameter
40 - "xfc-rp-inline":true, //Verwendete resourcen auflösen
41 - "xfc-rp-form-only":true, //Formular ohne HTML, BODY etc.
42 - "xfc-rp-usejq":false, //jQuery einbinden
43 - "xfc-rp-keepalive":false, //Ping zur Sessionverlängerung
44 - "xfc-rp-usecss":true, //Use Formcycle CSS files
45 - "xfc-rp-useui":true, //jQueryUI einbinden
46 - //Prozess-Parameter
47 - "xfc-pp-external":true, //Externer Formularrequest
48 - "xfc-pp-base-url":fcBase, //URL zum FormCycle
49 - "xfc-pp-success-url": myBase + "/anfrage-versendet.html", //CMS Seite bei erfolg
50 - "xfc-pp-error-url": myBase + "/anfrage-fehler.html" //CMS Seite bei Fehler
51 - },
52 - cache: false,
53 - async: false,
54 - success:function(html){
55 - myFormContainer.html(html);
56 - },
57 - crossDomain: true
58 - });
59 -}
60 -{{/code}}
68 + function renderFromLoginForm(element){
61 61  
70 + var form = element.closest('form');
71 + pass = $('INPUT[name=pass]', form),
72 + user = $('INPUT[name=user]', form);
62 62  
63 -== 5. Ergebenis Formular: ==
74 + if (user.val() && pass.val()) {
75 + render(user.val(), pass.val());
76 + }
77 + }
64 64  
65 -{{html clean="false"}}
66 - <div class="hljs" id="content"></div>
67 -{{/html}}
79 + function checkIsLogin(){
80 + $('.xfc-template .login INPUT[type=submit]', o.form_container).click(function(){
81 + renderFromLoginForm($(this));
82 + return false;
83 + }).addClass('xm-bound-login');
84 + }
68 68  
86 + function buildLoader(){
87 + o.form_container.html('');
69 69  
89 + var l = $('<div>').addClass('xm-form-loader-icon').appendTo(o.form_container);
90 + $('<style>').text(o.loadingImageStyle).appendTo(l);
91 + $('<img>').attr('src',o.loadingImageURL).appendTo(l);
92 + }
70 70  
94 + function render(user, pass){
95 + d = (user && pass) ? $.extend(d, {
96 + "xfc-rp-username": user,
97 + "xfc-rp-password": pass
98 + }) : d;
71 71  
100 + console.log(o.form_base + '/form/provide/' + o.form_id)
72 72  
102 + $.ajax($.extend({
103 + type: "GET",
104 + url: o.form_base + '/form/provide/' + o.form_id,
105 + data: d,
106 + cache: false,
107 + async: false,
108 + beforeSend:buildLoader,
109 + success: success,
110 + crossDomain: true
111 + }, options.ajax )).fail(error);
112 + }
73 73  
114 + o.form_id = o.form_id;
115 + o.form_container_id = (o.form_container_id) ? o.form_container_id : 'content';
116 + o.form_container = (o.form_container_id) ? $('#'+o.form_container_id) : o.form_container;
117 + o.form_container = (o.form_container) ? o.form_container : $('.tx-xm-formcycle, .xfc-template-body').first();
118 + o.form_base = o.form_base;
119 +
120 + if (o.data && o.data.hasOwnProperty("xfc-pp-base-url")) o.form_base = o.data["xfc-pp-base-url"];
121 + if (o.form_action == 'login') $(renderFromLoginForm(trigger)); else $(render);
122 +})(jQuery, options, trigger)})
74 74  
75 -Für das folgenden Beispiel wird zu Demonstrationszwecken eine eigene [[HTML-Seite>>attach:iframe.html]] in einem iframe dargestellt:
124 +jQuery( document ).ready(function() {
125 + window.xima.fc.form.load({form_container_id:'content', form_base:'https://demo7.formcycle.eu/formcycle', form_id:'564'});
126 +});
76 76  
77 -{{html clean="false"}}
78 - <style type="text/css">
79 - pre{
80 - margin:0;
81 - }
82 82  
83 - .xm-form{
84 - margin:0 auto;
85 - }
86 86  
87 - .extra .hljs-string{
88 - font-weight:bold;
89 - color:red;
90 - }
130 + </script>
131 + <style type="text/css">
132 + span.box{
133 + display: block;
134 + padding: 20px;
135 + }
136 + </style>{{/html}}
91 91  
92 - iframe, .hljs{
93 - max-width:700px;
94 - border:2px solid #515151;
95 - }
138 +Sie können das Formular direkt per AJAX ohne IFrames in Ihre Webseite einbinden. Unterstützung der möglichen Einbindungsoptionen finde Sie in FORMCYCLE direkt unter [[Veröffentlichen>>doc:Formcycle.UserInterface.MyForms.Publish.WebHome||target="_blank"]].
96 96  
97 - .hljs{
98 - max-width:985px;
99 - text-align:center;
100 - }
140 + {{code}} <!DOCTYPE html>
141 + <html>
142 + <head>
143 + <meta charset="utf-8">
144 + <!-- jQuery must be loaded-->
145 + <script src="https://demo7.formcycle.eu/formcycle/form/includes/010-jquery-min.js?_nc=1637667410192"></script>
146 + <!-- configure path to your server, the id of the content element where the form should placed into and id of the form.-->
147 + <script src="https://demo7.formcycle.eu/formcycle/form/include.js?auto=1&form_container_id=content&form_id=564&form_base=https://demo7.formcycle.eu/formcycle"></script>
148 + </head>
149 +
150 + <body class="body">
151 + <!-- this is the div where the form will be placed into -->
152 + <div id="content"></div>
153 + </body>
154 + </html>
155 + {{/code}}
101 101  
102 - .resizer {
103 - display:flex;
104 - margin:0;
105 - padding:0;
106 - resize:both;
107 - overflow:hidden
108 - }
109 -
110 - .resizer > .resized {
111 - flex-grow:1;
112 - margin:0;
113 - padding:0;
114 - border:0;
115 - height: inherit;
116 - }
117 - .border { border:4px dashed black; }
118 - </style>
119 -
120 - <div class="resizer border" style="height: 1000px;">
121 - <iframe id="customerdemo" class="resized" src="https://help7.formcycle.eu/xwiki/bin/download/Examples/IncludeAJAX/iframe.html"></iframe>
122 - </div>
157 +{{html clean="false"}}
158 + <div class="hljs" id="content"></div>
123 123  {{/html}}
iframe.html
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.gru
Größe
... ... @@ -1,1 +1,0 @@
1 -893 bytes
Inhalt
... ... @@ -1,22 +1,0 @@
1 -<!DOCTYPE html>
2 -<html>
3 - <head>
4 - <meta charset="utf-8">
5 - <!-- jQuery must be loaded-->
6 - <script src="https://demo7.formcycle.eu/formcycle/form/includes/010-jquery-min.js?_nc=1637667410192"></script>
7 - <!-- configure path to your server, the id of the content element where the form should placed into and id of the form.-->
8 - <script src="https://demo7.formcycle.eu/formcycle/form/include.js?auto=1&form_container_id=content&form_id=564&form_base=https://demo7.formcycle.eu/formcycle"></script>
9 - <style>
10 - h1.page, p.page {
11 - text-align: center;
12 - }
13 - </style>
14 - </head>
15 -
16 - <body class="body">
17 - <h1 class="page">Beispielwebseite</h1>
18 - <p class="page">Mit dem obenstehenden Code kann ein FORMCYCLE Formular per AJAX in die Website geladen werden.</p>
19 - <!-- this is the div where the form will be placed into -->
20 - <div id="content"></div>
21 - </body>
22 -</html>