Hello. I have a situation and was wanting some input on it.
I have a form that uses arrays for the inputs:
...
print "<INPUT TYPE='HIDDEN' NAME='id[]' VALUE='".OCIResult($stmt,1)."'>\n";
...
This is because I have no idea how many of these rows I will submit for update. Anyway, this approach works fine when I set my form action to submit to another page, which then does the updates and redirects to my original page. So I know the code as it stands works.
However, when I try to put this "form handler" into a function so I can distribute it amongst multiple pages, I run into problems when trying to utilize the form elements.
My form handler call is as such:
handle_form($HTTP_POST_VARS)
The function declaration is as such:
handle_form($form_vars)
Due to this arrangement, I seemingly have to handle the POST vars I passed in as:
$form_vars['key']
But this doesn't work with the form/input arrays I'm using:
$form_vars['$id[$count]']
and I can't access the values if I just use
$id[$count]
Can anybody tell me what I'm missing?
Thanks for your time.
Nested Post Variable Arrays
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Not really, mainly because I have a mix of form items being returned.
Some have only one instance, others may have N instances.
The example input I showed would be one of the N instance ones, which is why I am using the array. And there are multiple arrays within the form, as well.
Here's a glimpse:
...
while()
{
print "<INPUT TYPE='HIDDEN' NAME='savedesc[]' VALUE='".OCIResult($stmt,2)."'>\n";
print "<INPUT TYPE='HIDDEN' NAME='id[]' VALUE='".OCIResult($stmt,5)."'>\n";
print "<INPUT TYPE='HIDDEN' NAME='id2[]' VALUE='".OCIResult($stmt,7)."'>\n";
}
print "<INPUT TYPE='HIDDEN' NAME='TRACK' VALUE='".OCIResult($stmt,6)."'>\n";
...
Some have only one instance, others may have N instances.
The example input I showed would be one of the N instance ones, which is why I am using the array. And there are multiple arrays within the form, as well.
Here's a glimpse:
...
while()
{
print "<INPUT TYPE='HIDDEN' NAME='savedesc[]' VALUE='".OCIResult($stmt,2)."'>\n";
print "<INPUT TYPE='HIDDEN' NAME='id[]' VALUE='".OCIResult($stmt,5)."'>\n";
print "<INPUT TYPE='HIDDEN' NAME='id2[]' VALUE='".OCIResult($stmt,7)."'>\n";
}
print "<INPUT TYPE='HIDDEN' NAME='TRACK' VALUE='".OCIResult($stmt,6)."'>\n";
...
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
http://www.php.net/is_array
then you could just use an if() statement to tell if it has more than 1 instance...
then you could just use an if() statement to tell if it has more than 1 instance...
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
well since formvars is an array
do like
do like
Code: Select all
foreach($formvars as $key){
if(is_array($key)){
//do stuff with the arrays
} else {
//do stuff with the strings
}
}