开发者

PHP - select all inputs of class for form POST

开发者 https://www.devze.com 2023-04-11 21:54 出处:网络
I need to find a way to select all inputs of \"multiFiles\" so that I can post the values of these for a PHP processing script.I need a way to separate each input into separate PHP variables so that I

I need to find a way to select all inputs of "multiFiles" so that I can post the values of these for a PHP processing script. I need a way to separate each input into separate PHP variables so that I can upload into a database.

<input type="text" class="multiFiles">
<input type="text" class="multiFiles">
<input type="text" class="multiFiles">
<input type="text" class="multiFiles">
<开发者_C百科;input type="text" class="multiFiles">


You could use the array like so:

<input type="text" name="multiFiles[]" />
<input type="text" name="multiFiles[]" />
<input type="text" name="multiFiles[]" />

When submitted to the server, you can then do this to see how the information is handled (spoiler; it submits it as an array):

<?php
print_r($_POST["multiFiles"]);
?>


var i = 0, inputs = {};
$('.multiFiles').each(function() {
   inputs['file' + (++i)] = $(this).val();
});

$.post("someURL", inputs, function(response, textStatus, xhr) {
    //do something with response...
});


Two things:

1- In order to select all inputs, you can do: $(".multiFiles")

2- Add the "name" attribute to the input fields (with different names of course) in order to capture them on different variables on your php script.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号