I am trying to prepare a loop that will store the data from form fields below as a variable, that I can then use to create a new dynamic form based on this data.
FLOW EXAMPLE:
1. jquery submits hidden form in popup iframe(done)
2. PHP loops through POST from hidden form in iframe and outputs as new form in current popup iframe.
3. user selects the fields they wish to submit to database. Submits form.
4. database entry is added
5. selected fields are removed from current iframe. None selected are left.
I am stuck on the loop part of the code, I need an efficient solution that allows me to loop through POST and output a new form that the user can submit.
I know its alot to ask, but any help would be great, been banging my head against the wall trying to figure out how to do this. :(
Thanks, Steve
PS. Sometimes there will be 10 fields, sometimes 2....it all depends on what is on the page when the iframe is created. But there will always be the same number of each field. Like in my field example below.
EXAMPLE OF FIELDS (all hidden)
<input type="hidden" id="data[]" name="data[]" value="SOMETHING HERE">
<input type="hidden" id="data[]" name="data[]" value="SOMETHING BLAH BLAH">
<input type="hidden" id="data[]" name="data[]" value="BLAH BLAH SOMETHING">
<input type="hidden" id="info[]" name="info[]" value="MY INFO HERE">
<input type="hidden" id="info[]" name="info[]" value="RANDOM INFO HERE">
<input type="hidden" id="info[]" name="info[]" value="MORE INFO">
<input type="hidden" id="img[]" name="img[]" value="http://example.com/img2.gif">
<input type="hidden" id="img[]" name="img[]" value="http://example.com/someimage.jpg">
<input type="hidden" id="img[]" name="img[]" value="http://example.com/myimage.png">
<input type="hidden" id="title[]" name="title[]" value="Item title goes here">
<input type="hidden" id="title[]" name="title[]" value="Item title goes here ">
<input type="hidden" id="title[]" name="title[]" value="Item title goes here">
MY PHP loop I tried:
foreach ($_POST['data'] as $data=>$val){
echo "$data: $val <br />";
}
foreach ($_POST['info'] as $info=>$val){
echo "$info: $val <br />";
}
foreach ($_POST['img'] as $img=>$val){
echo "$img: $val <br />";
}
foreach ($_POST['title'] as $title=>$val){
echo "$title: $val <br />";
}
EXAMPLE PHP Output
0: €29.16
1: €34.46
2: €34.46
3: €63.62
4: €53.02
5: €10.60
6: €42.42
0: ../img1.gif
1: ../img2.jpg
2: ../img3.jpg
3: ../img4.png
4: ../img5.gif
5: ../img6.jpg
6: ../img7.jpg
etc...
Example of how the output needs to be structured in the new form:
Item 1 Item 2 item 3 item 4
Title0 title1 title2 title3
info0 info1 info2 info3
img0 img1 img2 img3
data0 data1 data2 data3
checkbox checkbox checkbox checkbox
SUBMIT BTN
var_dump's. I can't honestly say I see any attemt at structuring the output, let alone structure it in a way that adheres to the desired output, nor do you specify what about generating that output isn't working for you (descibe specifc problem)var_dumpdoesn't come supplied with checkboxes and submit buttons.echo "$data: $val <br />";is practically the same asecho "$data => $val, <br />";, add anecho 'array (', count($_POST['data']), ') {<br/>';before and after the loops and you must admit: it's pretty similar, isn't it?