Php 聚合铁表单post方法不起作用$\u post变量为空
当我使用post方法Php 聚合铁表单post方法不起作用$\u post变量为空,php,forms,polymer,polymer-1.0,polymer-starter-kit,Php,Forms,Polymer,Polymer 1.0,Polymer Starter Kit,当我使用post方法时,铁的形式不起作用,但是get方法起作用。 以下是代码: test.php: <script> document.addEventListener("WebComponentsReady",function() { document.querySelector("#form").addEventListener('iron-form-submit',function(e){ }); document
时,铁的形式不起作用,但是get方法起作用。
以下是代码:
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>
根据您的网络日志iron form
工作正常,问题一定出在PHP方面
乍一看,您似乎正在提交给/user/put
,但您的var_dump
位于索引中。php
,请确保您的文件路径正确。根据您的网络日志iron form
工作正常,问题一定出在php方面
乍一看,您似乎正在提交给/user/put
,但您的var_dump
位于索引中。php
,请确保您的文件路径正确。也许这是因为使用iron form POST数据以JSON格式发送,请查看浏览器开发工具参数选项卡以查看发送的内容
php脚本中的var_dump($_POST)如果未解码,则返回空字符串
尝试使用文件获取内容php://input 要在服务器端访问I/O流和json_解码,如下所示:
服务器端php脚本:
<?php
$datas = file_get_contents("php://input");
$_POST = json_decode($datas, true);
$return = '<ul>';
foreach($_POST as $index=>$val) {
$return .= '<li>'.$index.'/'.$val.'</li>';
}
$return .= '</ul>';
echo '{"my_return": "'.$return.'"}';
这可能是因为使用iron form POST数据以JSON格式发送,请查看浏览器开发工具参数选项卡以查看发送的内容
php脚本中的var_dump($_POST)如果未解码,则返回空字符串
尝试使用文件获取内容php://input 要在服务器端访问I/O流和json_解码,如下所示:
服务器端php脚本:
<?php
$datas = file_get_contents("php://input");
$_POST = json_decode($datas, true);
$return = '<ul>';
foreach($_POST as $index=>$val) {
$return .= '<li>'.$index.'/'.$val.'</li>';
}
$return .= '</ul>';
echo '{"my_return": "'.$return.'"}';
all请求全部重定向到index.php。它运行并var\u dump($\u POST)代码>它的输出也在响应中显示为空,我将其附加在imageall请求中,所有重定向到index.php。它运行并var\u dump($\u POST)代码>其输出也显示为响应,其中为空。我将其附加在图像中。嗯,这是有效的,但为什么polymer团队在任何文档中都没有提到它?现在还有一件事,我如何根据您的解决方案使用iron表单上传文件?只有文件路径在$u POST变量中传递,而$u FILES变量为空?嗯,这是有效的,但为什么polymer团队在任何文档中都没有提到它吗?现在还有一件事,我如何根据您的解决方案使用iron表单上传文件?只有文件路径在$\u POST变量中传递,而$\u FILES变量为空?
<?php
$datas = file_get_contents("php://input");
$_POST = json_decode($datas, true);
$return = '<ul>';
foreach($_POST as $index=>$val) {
$return .= '<li>'.$index.'/'.$val.'</li>';
}
$return .= '</ul>';
echo '{"my_return": "'.$return.'"}';
<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>