/    Sign up×
Community /Pin to ProfileBookmark

Multiple foreach $_POST

Okay, I have a series of files that essentially creates 5 php files for a program I am writing. It currently writes 4 of the needed files and I’m about to start on the fifth. However, I’ve come to the realization of a problem. The originating file creates dynamic inputs based on the users original input. If they enter say ‘7’ for the number of fields, this will create 7 subsets of 3 inputs which will allow them to input the name (first input) of the type (second input) of an entry field and then enter the size (third input) of the entry field. So if they enter 7 they will have 7 sets of inputs, each allowing them to enter Name, Type and Size. If these fields are then entered as [I]item_number, text, 15[/I] respectively, the final output will be:

[CODE]
<input type=’text’ name=’item_number’ size=’15’>
[/CODE]

Hope this is making sense so far.

So in each of my 4 files, I’ve only been concerned with the name entered but this final file will have to include all 3 as this will be the file created for final user input. My previous entries have been declared by foreach($_POST[‘name’] as $value) and then I can go from there. However, since I will actually have to pull all of these without knowing how many fields the user has selected, how should I do this? The originating file writes this code for the number of entries, $i, the user has input.

[CODE]
for ($i=1;$i<=$number_of_fields;$i++)
{
print “<tr><td height=17 bgcolor=’#7E7C53′ colspan=3 align=center><font class=’title’>Input #$i</font></td></tr>n”;
print “<tr><td colspan=3 height=10></td></tr>n”;
print “<tr><td align=center><input type=’text’ name=’name[$i]’ size=’15’></td>n”;
print “<td align=center><select name=’field_type[$i]’><option value=”></option><option value=’text’>Text</option><option value=’textarea’>Text Area</option><option value=’hidden’>Hidden</option></td>n”;
print “<td align=center><input type=’text’ name=’size[$i]’ size=’5′></td></tr>n”;
print “<tr><td align=center>Field Name</td><td align=center>Field Type</td><td align=center>Size</td></tr>n”;
print “<tr><td colspan=3 height=10></td></tr>n”;
}
[/CODE]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @ephmynus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...