PHP - select all inputs of class for form POST
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.
精彩评论