admin管理员组文章数量:1327945
I'm working on a form upload element that can be used in the Zend Framework forms. I'm trying to make it so the programmer can use it in any project without having to manually configuring any settings.
The files are uploaded by an AJAX uploader which returns JSON data like:
[
{
"name":"image.png",
"size":42410,
"type":"image\/png",
"url":"http:\/\/example\/image.png",
"thumbnail_url":"http:\/\/example\/thumbnail\/image.png",
}
]
Since the uploader itself is a form element I'm trying to put that data in the form so on the submit the values can be retrieved from the $_POST. I was adding hidden input fields with javascript named uploader-data[] (when submitting the form) but that only allows me to pass 1 variable at the time to the hidden field.
So I guess my question is: "How can I pass the whole array/object to the $_POST / form?". Even though I am using AJAX for the uploader itself I don't want to use it to submit the form. I want a regular form submit containing all the data from the JSON object/array. The files itself are already uploaded but I might want to use the JSON data in my database or at some other place.
Is it possible to do something like this?
Thanks in advance.
I'm working on a form upload element that can be used in the Zend Framework forms. I'm trying to make it so the programmer can use it in any project without having to manually configuring any settings.
The files are uploaded by an AJAX uploader which returns JSON data like:
[
{
"name":"image.png",
"size":42410,
"type":"image\/png",
"url":"http:\/\/example.\/image.png",
"thumbnail_url":"http:\/\/example.\/thumbnail\/image.png",
}
]
Since the uploader itself is a form element I'm trying to put that data in the form so on the submit the values can be retrieved from the $_POST. I was adding hidden input fields with javascript named uploader-data[] (when submitting the form) but that only allows me to pass 1 variable at the time to the hidden field.
So I guess my question is: "How can I pass the whole array/object to the $_POST / form?". Even though I am using AJAX for the uploader itself I don't want to use it to submit the form. I want a regular form submit containing all the data from the JSON object/array. The files itself are already uploaded but I might want to use the JSON data in my database or at some other place.
Is it possible to do something like this?
Thanks in advance.
Share Improve this question asked Dec 8, 2011 at 14:50 IliansIlians 7437 silver badges23 bronze badges1 Answer
Reset to default 6Put your javascript value into an input field using JSON.stringify :
data = [
{
"name":"image.png",
"size":42410,
"type":"image\/png",
"url":"http:\/\/example.\/image.png",
"thumbnail_url":"http:\/\/example.\/thumbnail\/image.png",
}
]
document.getElementById('my_hidden_input').value = JSON.stringify(data);
This will turn your array in the following text value:
[{"name":"image.png","size":42410,"type":"image/png","url":"http://example./image.png","thumbnail_url":"http://example./thumbnail/image.png"}]
Zend can parse the JSON value into a php array.
本文标签: Passing a javascript array to a formPOST without ajaxStack Overflow
版权声明:本文标题:Passing a javascript array to a form$_POST without ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742224640a2435982.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论