php - Polymer iron-form post method not working $_POST variable empty -


when use post method iron-form not work method works. here code:

test.php:

<script>     document.addeventlistener("webcomponentsready",function() {         document.queryselector("#form").addeventlistener('iron-form-submit',function(e){             });         document.queryselector("#form").addeventlistener('iron-form-response',function(e){             console.log(e);         });         document.queryselector("#form").addeventlistener('iron-form-error',function(e,s,d){             console.log(e);             alert('iron form error!');         });     }); </script> <body>     <form is="iron-form" id="form" method="post" action="/user/put">         <input name="address" required>         <input type="submit" value="submit" >     </form> </body> 

index.php:

<?php     var_dump($_post); ?> 

when submit form screenshot of headers innetwork tab: screenshot of headers in network tab when form submit

response tab:

array(0) { } 

maybe because using iron-form post datas sent in json format, @ browser developper tools params tab see sent !

var_dump($_post) in php script return empty string if not decoded.

try file_get_contents php://input access i/o stream , json_decode on server side, this:

server side php script:

<?php $datas = file_get_contents("php://input"); $_post = json_decode($datas, true);  $return = '<ul>'; foreach($_post $index=>$val) {     $return .= '<li>'.$index.'/'.$val.'</li>'; } $return .= '</ul>';  echo '{"my_return": "'.$return.'"}'; 

and polymer component:

<dom-module id="my-form">     <template>         <div class="horizontal center-center layout">             <div>                 <div class="horizontal-section">                     <form is="iron-form" id="formget" method="post" action="add.php">                         <paper-input name="name" label="name" value="john doe" required></paper-input>                         <paper-input name="age" label="age" value="97" required></paper-input>                         <br><br><br>                         <paper-button raised onclick="clickhandler(event)">submit</paper-button>                     </form>                 </div>             </div>         </div>     </template>     <script>          function clickhandler(event) {             polymer.dom(event).localtarget.parentelement.submit();         }          polymer({             is: 'my-form',             listeners: {                 'iron-form-response': 'formresponse',                 'iron-form-submit': 'formsubmit',                 'iron-form-error': 'formerror'             },             formerror: function(e) {                 alert(e.detail.error);         },         formsubmit: function(e) {             //alert(document.getelementbyid("formget").serialize().name);             //alert(document.getelementbyid("formget").serialize().age);         },         formresponse: function(e) {              document.getelementbyid('contenteclp').innerhtml = e.detail.my_return;        }     }); </script> 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -