用POST方法和聚合物铁形式发送表格? [英] Sending form with POST method and Polymer iron-form?
问题描述
我使用Polymer starter kit 1.0.2,我试图使用基于(小)文档的铁形式。
我的方法形式是 post,并且只包含一个输入。
我的表单action是一个PHP脚本(add.php),显示$ _GET和$ _POST的内容:
print_r($ _ POST);
print_r($ _ GET);
我的表单组件(form_eclp.html)是:
< dom-module id =my-form>
< template>
< div class =水平中心布局>
< div>
< div class =horizontal-section>
< form is =iron-formid =formGetmethod =postaction =add.php>
< paper-input name =namelabel =Namerequired>< / paper-input>
< br>< br>< br>
< paper-button raised onclick =clickHandler(event)> Submit< / paper-button>
< / form>
< / div>
< / div>
< / div>
< / template>
< script>
函数clickHandler(event){
Polymer.dom(event).localTarget.parentElement.submit();
}
聚合物({
是:'my-form',
听众:{
'iron-form-response':'formResponse'
},
formResponse:function(e){
// ?????????
}
});
< / script>
< / dom-module>
我打电话给if:
< link rel =importhref =form_eclp.html>
< my-form>< / my-form>
当我在名称输入中输入文本'test'后点击提交按钮时,我可以看到浏览器的网络选项卡开发工具,它是一个POST请求,好的,但网址是add.php?name = test,并且在响应选项卡中我有:
<$数组
(
)
数组
(
[名称] =>测试
)
根据我的表单动作(add.php脚本),第一个数组用于$ _POST,第二个数组用于$ _GET。
我可以看到,尽管form method =post,它是一个get请求,因为只填充了$ _GET,$ _POST中没有任何内容。 >
我不明白,它是一个错误吗?
看起来你的bower.json中的表单输入已经过时了。做到这一点:凉亭安装-S PolymerElements /铁形式,一切都应该罚款。
i use Polymer starter kit 1.0.2 and i'm trying to use iron-form based on (little) documentation i found.
My method form is "post" and contain only one input.
My form "action" is a PHP script (add.php) showing content of $_GET and $_POST:
print_r($_POST);
print_r($_GET);
My form component (form_eclp.html) is:
<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" 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'
},
formResponse: function(e) {
// ?????????
}
});
</script>
</dom-module>
I call if from:
<link rel="import" href="form_eclp.html">
<my-form></my-form>
When i click the submit button after entering the text 'test' in name input, i can see in the network tab of the browser developper tools that it's a POST request, ok, but the url is add.php?name=test, and in the response tab i have:
Array
(
)
Array
(
[name] => test
)
According to my form action (add.php script), first array is for $_POST and the second $_GET.
I can see, despite form method="post", it's a "get" request because only $_GET is populated, there is nothing in $_POST.
I don't understand, is it a bug ?
So it seems like the form-input is outdated in your bower.json. Do this: bower install -S PolymerElements/iron-form and everything should be fine.
这篇关于用POST方法和聚合物铁形式发送表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!