Jump to content

[SOLVED] Name Values in forms/retrieving information when line items are of unknown #


Recommended Posts

Here is the situation:

 

I have written a parser to go through a log file and pull out the info needed.  This will produce specific items to match to the database which may come up with 1 or more results, returning the information into another form for the user to select which is appropriate (when more than one) or store the information in a hidden field (when there is only one).

 

I created this form by counting the items then:

 

foreach ($AllItems as $key => $value) 
{$fieldtally++;
echo "<tr><th class=\"headTH\" colspan=\"2\">";
echo $key;
echo "</th></tr>\n";
foreach ($value as $v)
	{$choices = count($value);
	if ($choices > "1")
		{if ($cssCt2 %2)
			{echo "<tr><td><input type=\"radio\" name=\"chosenItem$fieldtally\" value=\"($key) $v\"></td><td>$v</td></tr>\n";}
		else
			{echo "<tr><td class=\"one\"><input type=\"radio\" name=\"chosenItem$fieldtally\" value=\"($key) $v\"></td><td class=\"one\">$v</td></tr>\n";}
		$cssCt2++;}
	else
		{echo "<input type=\"hidden\" name=\"chosenItem$fieldtally\" value=\"($key) $v\">\n";}
	}
}

 

I now have (in this particular instance), 9 post data named chosenItem#.  (ie: chosenItem1, chosenItem2, etc) Typically when wanting to use this information, I would set the variables:

 

$chosenItem1 = $_POST['chosenItem1'];

and so on.  But as the amount of items (and there for 'chosen items') will vary every time, I would like to automate that and stick in an array - and this is where I am stuck.

 

	if ($formcount <= $totalDiffItems)
	{$formcount++;
	$chosenItems = array($_POST['chosenItem???']);}

 

The ? ? ? is where I am stuck.  I have tried just adding $formcount, as well as ".$formcount." in various formations and know there must be a way to do this as there will be many instances where the fields are auto-generating and of unknown number - alas I am unsuccessful in my search not having even a vague idea what it may be called.

 

I'm sure someone else can explain much better, if I am completely confusing, please let me know how I can clarify.  Any points in the proper direction would be appreciated.

tia!

 

	while($formcount < $totalDiffItems)
	{$formcount++;
	$chosenItem = $_POST["chosenItem".$formcount.""];
	$chosenItems[] = $chosenItem;}

 

Found it on my own.  Answer should anyone else need something like this - It may not be pretty, but it seems to work.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.