I am using redbean to create my site and I am currently implementing a recipe upload feature for users.
In the 'upload recipe' form I have used javascript to dynamically add 4 input fields together (amount, measurement, ingredient, notes). I don't however know how to use redbean to store these once the user clicks submit. Could anyone suggest something? Would I have to use a loop to loop through each field added and store it to the database?
Here is the code I am using:
var count = 0;
$(function(addfield){
$('p#add_field').click(function(){
count += 1;
$('#container').append(
'<strong>Ingredient ' + count + '</strong><br />'
+ '`<`input id="field_' + count + 'name="amount" type="text" placeholder="Amount" `/>`' +
'<input id="field_' + count + 'name="measurement" type="text" placeholder="Measurement" `/>`'+
'<input id="field_' + count + 'name="ingredient" type="text" placeholder="Ingredient" `/>`' +
'<input id="field_' + count + 'name="notes" type="text" placeholder="Notes" `/>`' +
);
});
});
And this is the link to call the function:
<p id="add_field"><a href="#addfield"><span>» Click to add ingredient</span></a></p>