How to work with data returned after form submit












0















I have an AMP form that calls a web service on submit, and after that, I have a JSON as result. The JSON contains data and in order to see them, I am using amp-mustache template in submit-success div. And all is working fine. I see all the data I need.
But I am unable to access that data from outside the submit-success div. Since I need to set some controls on my form that are out of submit-success div, I need to access the JSON result outside thesubmit-success div.
Can anybody share how can I do this?










share|improve this question





























    0















    I have an AMP form that calls a web service on submit, and after that, I have a JSON as result. The JSON contains data and in order to see them, I am using amp-mustache template in submit-success div. And all is working fine. I see all the data I need.
    But I am unable to access that data from outside the submit-success div. Since I need to set some controls on my form that are out of submit-success div, I need to access the JSON result outside thesubmit-success div.
    Can anybody share how can I do this?










    share|improve this question



























      0












      0








      0








      I have an AMP form that calls a web service on submit, and after that, I have a JSON as result. The JSON contains data and in order to see them, I am using amp-mustache template in submit-success div. And all is working fine. I see all the data I need.
      But I am unable to access that data from outside the submit-success div. Since I need to set some controls on my form that are out of submit-success div, I need to access the JSON result outside thesubmit-success div.
      Can anybody share how can I do this?










      share|improve this question
















      I have an AMP form that calls a web service on submit, and after that, I have a JSON as result. The JSON contains data and in order to see them, I am using amp-mustache template in submit-success div. And all is working fine. I see all the data I need.
      But I am unable to access that data from outside the submit-success div. Since I need to set some controls on my form that are out of submit-success div, I need to access the JSON result outside thesubmit-success div.
      Can anybody share how can I do this?







      amp-html






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 6:11









      Chris Aby Antony

      71538




      71538










      asked Nov 13 '18 at 15:22









      IvanIvan

      65




      65
























          1 Answer
          1






          active

          oldest

          votes


















          1














          One way of doing it would be by saving your JSON response to a state. You can do this by using the on attribute of the form to set the state on the event submit-success as follows:



          <form id="form123" 
          action-xhr="/formHandle"
          method="POST"
          on="submit-success:AMP.setState({ msg : event.response.message })"
          >


          Now you can use this state to implement your control logic anywhere in your page by using it with an amp-bind expression. For example,



          <p class="" [text]=" 'Response is :' + msg">


          If you just want to perform common actions like hide, show, toggling accordion, scroll, opening a ligthbox etc., you can do this by using the corresponding AMP action inside the on attribute against the submit-success event, without having to use amp-bind.






          share|improve this answer
























          • This works. Now, how can I set the returned value to a PHP variable in the very same (asynchronous) post back (without a need to do another post back)?

            – Ivan
            Nov 19 '18 at 9:24











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284201%2fhow-to-work-with-data-returned-after-form-submit%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          One way of doing it would be by saving your JSON response to a state. You can do this by using the on attribute of the form to set the state on the event submit-success as follows:



          <form id="form123" 
          action-xhr="/formHandle"
          method="POST"
          on="submit-success:AMP.setState({ msg : event.response.message })"
          >


          Now you can use this state to implement your control logic anywhere in your page by using it with an amp-bind expression. For example,



          <p class="" [text]=" 'Response is :' + msg">


          If you just want to perform common actions like hide, show, toggling accordion, scroll, opening a ligthbox etc., you can do this by using the corresponding AMP action inside the on attribute against the submit-success event, without having to use amp-bind.






          share|improve this answer
























          • This works. Now, how can I set the returned value to a PHP variable in the very same (asynchronous) post back (without a need to do another post back)?

            – Ivan
            Nov 19 '18 at 9:24
















          1














          One way of doing it would be by saving your JSON response to a state. You can do this by using the on attribute of the form to set the state on the event submit-success as follows:



          <form id="form123" 
          action-xhr="/formHandle"
          method="POST"
          on="submit-success:AMP.setState({ msg : event.response.message })"
          >


          Now you can use this state to implement your control logic anywhere in your page by using it with an amp-bind expression. For example,



          <p class="" [text]=" 'Response is :' + msg">


          If you just want to perform common actions like hide, show, toggling accordion, scroll, opening a ligthbox etc., you can do this by using the corresponding AMP action inside the on attribute against the submit-success event, without having to use amp-bind.






          share|improve this answer
























          • This works. Now, how can I set the returned value to a PHP variable in the very same (asynchronous) post back (without a need to do another post back)?

            – Ivan
            Nov 19 '18 at 9:24














          1












          1








          1







          One way of doing it would be by saving your JSON response to a state. You can do this by using the on attribute of the form to set the state on the event submit-success as follows:



          <form id="form123" 
          action-xhr="/formHandle"
          method="POST"
          on="submit-success:AMP.setState({ msg : event.response.message })"
          >


          Now you can use this state to implement your control logic anywhere in your page by using it with an amp-bind expression. For example,



          <p class="" [text]=" 'Response is :' + msg">


          If you just want to perform common actions like hide, show, toggling accordion, scroll, opening a ligthbox etc., you can do this by using the corresponding AMP action inside the on attribute against the submit-success event, without having to use amp-bind.






          share|improve this answer













          One way of doing it would be by saving your JSON response to a state. You can do this by using the on attribute of the form to set the state on the event submit-success as follows:



          <form id="form123" 
          action-xhr="/formHandle"
          method="POST"
          on="submit-success:AMP.setState({ msg : event.response.message })"
          >


          Now you can use this state to implement your control logic anywhere in your page by using it with an amp-bind expression. For example,



          <p class="" [text]=" 'Response is :' + msg">


          If you just want to perform common actions like hide, show, toggling accordion, scroll, opening a ligthbox etc., you can do this by using the corresponding AMP action inside the on attribute against the submit-success event, without having to use amp-bind.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 5:04









          Chris Aby AntonyChris Aby Antony

          71538




          71538













          • This works. Now, how can I set the returned value to a PHP variable in the very same (asynchronous) post back (without a need to do another post back)?

            – Ivan
            Nov 19 '18 at 9:24



















          • This works. Now, how can I set the returned value to a PHP variable in the very same (asynchronous) post back (without a need to do another post back)?

            – Ivan
            Nov 19 '18 at 9:24

















          This works. Now, how can I set the returned value to a PHP variable in the very same (asynchronous) post back (without a need to do another post back)?

          – Ivan
          Nov 19 '18 at 9:24





          This works. Now, how can I set the returned value to a PHP variable in the very same (asynchronous) post back (without a need to do another post back)?

          – Ivan
          Nov 19 '18 at 9:24


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284201%2fhow-to-work-with-data-returned-after-form-submit%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python