Any checkbox experts out there.
I have checkboxes named assnid$assnarray[assnid].
Can anyone tell me how to pass these to a new page to preview the choices and then input the values into a database upon submit at that page?
Any checkbox experts out there.
I have checkboxes named assnid$assnarray[assnid].
Can anyone tell me how to pass these to a new page to preview the choices and then input the values into a database upon submit at that page?
I have my doubts that you actually use:
<input type="checkbox" name="assnid$assnarray[assnid]">
or are you really using that?
Basically, how does it look like on output?
Could you simplify the name to say:
assnid[0]
or just
assnid[]
?
if you use this
<input type="checkbox" name="assnid$assnarray[assnid]">
then after process, it will become
$assnid$assnarray[assnid] ...
so, i haven't code to that level...
i am not sure about ur problem, but i guess you want to let the user to see their checked items before you add it to the database... am i right?
Hi,
there is another problem. You use php code within html code without php tags.
You probably meant
<input type="checkbox" name="assignid" value="<?PHP echo $assnarray['assnid']; ?>">
or
<input type="checkbox" name="assignid" value="<?=$assnarray['assnid'] ?>">
Regards,
Thomas
Thanks laserlight and jimson,
I hope you can help me with this.
posted by jimson
i am not sure about ur problem, but i guess you want to let the user to see their checked items before you add it to the database... am i right?
Yes jimson that's exactly what I want to do!
posted by laserlight
I have my doubts that you actually use:<input type="checkbox" name="assnid$assnarray[assnid]">
or are you really using that?
Actually my checkbox looks like this:
<input type=checkbox name=assnid$assnarray[assnid] value=1>
Why? Because I'm modifying an old unsupported postnuke module and copying someone else's work. For another series of check boxes (going into a different table I might add) he wrote:
<input type=checkbox name=subcatid$subcatarray[subcatid] value=1>
Then he prints the selected values on the next page (for approval) with the following:
<?php
$boxstuff = "";
$boxTitle = "".ifconstant($catarray[catname])."";
$sql="select * from $pntable[yp_subcategory] where catid = $catarray[catid] order by subcatname";
$result2=mysql_query($sql);
while ($subcatarray = mysql_fetch_array($result2)) {
for ($i = 0; $i < $numids;$i++) {
if ($subcatidarray[$i] == $subcatarray[subcatid]) $boxstuff .= "\n<font size=1>".ifconstant($subcatarray[subcatname])."<br>";
}
}
$boxstuff .= "";
$row[title] = $boxTitle;
$row[content] = $boxstuff;
themesidebox($row);
?>
In functions.php, it appears he passes the array from page to page with the following:
<?php
for ($i = 0; $i < $numids;$i++) {
echo "\n<input type=hidden name=subcatid$subcatidarray[$i] value=1>";
}
?>
But that just confused me because I couldn't figure out how it came to be called that. After probing around, I found the following function in a different file (index.php). Now I'm not sure how it works but I think this is how subcatid$subcatarray[ ] becomes $subcatidarray. Am I right?
function parsevars() {
global $HTTP_POST_VARS,$subcatidarray;
if (is_array($HTTP_POST_VARS)) {
$idarray=array_keys($HTTP_POST_VARS);
$numids = count($idarray);
$cnt = 0;
for ($i=0;$i < $numids; $i++) {
if ($idarray[$i] <> "Submit" && substr($idarray[$i],0,8)=="subcatid") {
$subcatidarray[$cnt++] = substr($idarray[$i],8);
}
}
}
}
One last question I have to ask jimson. Are you really a Bee Gees fan?!
Hi Thomas. I appreciate your input too.
posted by tsinka
there is another problem. You use php code within html code without php tags.You probably meant
<input type="checkbox" name="assignid" value="<?PHP echo $assnarray['assnid']; ?>">
or
<input type="checkbox" name="assignid" value="<?=$assnarray['assnid'] ?>">
I'm sorry for not being clear. I was trying to summarize this so I left the rest out. It is written like this:
<?php
$catarray = mysql_fetch_array($result);
echo "\n<tr><td>\n";
$boxstuff = "";
$boxTitle = "".ifconstant($catarray[catname])."";
$sql="select * from $pntable[yp_subcategory] where catid = $catarray[catid] order by subcatname";
$result2=mysql_query($sql);
while ($subcatarray = mysql_fetch_array($result2)) {
$boxstuff .= "<input type=checkbox name=subcatid$subcatarray[subcatid] value=1> ";
$boxstuff .= "\n<font class=\"pn-normal\">".ifconstant($subcatarray[subcatname])."<br>\n";
}
$boxstuff .= "";
$row[title] = $boxTitle;
$row[content] = $boxstuff;
themesidebox($row);
echo "\n</td></tr>\n";
?>
Hey! Where'd everybody go?
ok, i understand your problem...
so, if you see this line
// code in php context
$boxstuff .= "<input type=checkbox name=subcatid$subcatarray[subcatid] value=1> ";
so the result is the name for the checkbox will then replace with subcatidXXXXXXX where the XXXXXXX value come from the $subcatarray['subcatid']. Let say the $subcatarray['subcatid'] is a word 'jimson', so the checkbox actually named subcatidjimson when it get parsed.
so, in order to retrieve the posted data on the subsequent page, you will use $_POST['subcatidjimson'].
I want to know if you are using register_globals = On in your php.ini file.
function parsevars() {
global $HTTP_POST_VARS,$subcatidarray;
// so in my example above, my $_POST will contained $_POST['subcatidjimson'] = 1
if (is_array($HTTP_POST_VARS)) {
$idarray=array_keys($HTTP_POST_VARS);
// so $idarray now is
// array (
// [0] = subcatidjimson
// )
$numids = count($idarray);
// $numids = 1
$cnt = 0;
for ($i=0;$i < $numids; $i++) {
if ($idarray[$i] <> "Submit" && substr($idarray[$i],0,8)=="subcatid") {
// so $idarray[0] is not submit and the substr $idarray[0],0,8 is equal to
// subcatid
$subcatidarray[$cnt++] = substr($idarray[$i],8);
// now $subcatidarray <= this variable is global scope
// $subcatidarray[0] = jimson
}
}
}
}
I think I solve the part how the posted input id become available in $subcatidarray.
see the code after this paragraph
Then he prints the selected values on the next page (for approval) with the following:
Ok, you said you want to display the selected item in the next page for approval but, it seems the code are getting data from the database
while ($subcatarray = mysql_fetch_array($result2)) {
he use the $subcatarray to fetch the data from database.
and i really wonder how he can display the posted checkbox in the confirmation page... you provided me with insufficient code to understand your problem.
Hi jimson!
Thanks for coming back.
You're right about the parsing to subcatidjimson, in this case, it's actually a number (not that you really thought it was jimson), so it would be subcatid111 or whatever. As for using $_POST['subcatidjimson'], that's what I thought too but it's not to be found. He's doing it another way.
Right again about the database. It's a postnuke module and everything either comes from or goes to a data table. The way the original programmer set it up, the subcategories (a table) subcatarray are sorted and printed under their respective categories (another table) catarray. Hence the extra query.
When he publishes the checkbox selections, he lists all categories but only those subcategories that are selected on the previous page. This is done in multiple columns...I messed with that and I've got to admit it was a real hastle.
I think the answer is yes to your question about globals. I really don't understand how to do that but I think that's what he's doing.
So what can you tell me about the parsevars function? I'd really like to figure out what he's doing there and how I could (assuming I'd want to) tweak it to work with my assnidarray. (I'm sorry for digressing but that sounds like a punchline)
If it'd help, I could attach the files but, out of respect for our host, I didn't want to do that unless someone wanted to see them.
you ask
So what can you tell me about the parsevars function? I'd really like to figure out what he's doing there and how I could (assuming I'd want to) tweak it to work with my assnidarray.
so, first, buddy, do you really read my post?
do you see the comment text i put when i describe what the function did for you to understand!:mad: and yet you ask to tell you about the parsevars function which i already explained...?:mad:
Jimson,
I'm sorry. I'm nearly blind and it's almost impossible for me to read the orange on grey. My mistake, it was late. I was focused on answering your questions and and I thought you were quoting. Once I copied and pasted it so I had black print on a white background, I saw your annotations (which I appreciate).
I really am grateful for your input and I feel pretty stupid right now. I need to be more careful. I'm sorry.
i forgive you....
Hey jimson!
Noticed your signature, went over to the pHP website, poked around and found the manual dowload. Unfortunately (fortunately?), aside from the language choices (an easy selection) it's offered in just about every flavor. I don't think I want to put it on my Palm and I'll probably put it on both Windows and Mac boxes any thoughts on which version(s) I should choose? For example, am I going to like the single html download or the many html download?
EFJ
http://www.php.net/download-docs.php
for your windows . get the .chm (Windows HTML Help)
for your palm pilot, get either doc.pdb or isilo.pdb
don't get the single HTML for windows... it is for people in somewhere.
get the multiple one and unzip the it, but take quite some time.
Thanks...I'll check it out...along with the postnuke docs, the mysql docs, and the adodb docs and...did I forget anything?