0

I am developing a system for equipment rental in PHP.

I need to send a form that contains the id, quantity, time and value fields of the selected equipment. Each rent can have N equipments, consequently N amount of fields.

How do I do this? Do I generate the fields by javascript? To send, an array for each piece of equipment?

It would be something like that:

<input type='text' name='equipment[]'>
<input type='text' name='quantity[]'>
<input type='text' name='time[]'>

But how would I do it like this:

array(array[0](equipment=>1,quantity=>2,time=>4),array[1](equipment=>2,quantity=>2,time=>4),array[2](equipment=>1,quantity=>2,time=>4));
Kara
  • 6,115
  • 16
  • 50
  • 57
Edvainer Reis
  • 31
  • 1
  • 6
  • 1
    Can you share some code of what you've tried to so far? You likely need to use an array for the form fields https://stackoverflow.com/questions/3314567/how-to-get-form-input-array-into-php-array – kyle Oct 23 '17 at 16:10

2 Answers2

0

A small example :

HTML:

 <div id="content">
<input type="text" class="fieldone" id="fields_1" name="fields[]"/>

</div><input type="button" id="addmore" />

Jquery:

counter=1;
$(document).on('click','#addmore',function(){
counter++;
var htmltoadd='<input type="text" class="fieldone" id="fields_"'+counter+' name="fields[]"/>';
$("#content").append(htmltoadd);
});

You need to include jquery in this example.

Blesson Christy
  • 380
  • 3
  • 13
0

I think you could group by rental doing like this:

<div id="rental_group_1">
    <input type="text" name="rent_1[]" id="equipment_1">
    <input type="text" name="rent_1[]" id="quantity_1">
    <input type="text" name="rent_1[]" id="time_1">
</div>
<div id="rental_group_2">
    <input type="text" name="rent_2[]" id="equipment_2">
    <input type="text" name="rent_2[]" id="quantity_2">
    <input type="text" name="rent_2[]" id="time_2">
</div>...

This way you will get on Post an array per group so:

$rent_1[0] = equipment_1
$rent_1[0] = quantity_1
$rent_1[0] = time_1
...

Adding this to @Blesson Christy solution will create a good UI/UX for what you want. Hope it helps! :D

ArtFranco
  • 300
  • 3
  • 10