Jump to content

checkboxes help


friedice

Recommended Posts

for example i have a form like this

<form name="input" action="page2.php" method="post">

<table cellpadding="20" width="100%">
<!-- BEGIN query -->								


								<tr>
								<td>
								<img src="../eImages/{IMAGE}.jpg" style="width:200px;height:200px;" />

                                                   </td>
											   <td>

								{EVENTTYPE}</br>
								{DPLACE} </br>
								{NAME}</br>
								{SPEAKERS}</br>
								{LOC}</br>
								{STREET}</br>
								{TIME} </br>
								</td>

								<td>
								<input type="checkbox" name="eventlist">

								</td>
								</tr>
<!-- END query -->			

	</table>
<input type="submit" value="Submit" />
</form>

 

this is all dynamically loaded each time from a database so it could have several trs of this formal

my goal is to only select 3 of them and then submit the form

this is will make a checkbox for each one including all the details

but the problem is that the checkboxes will all have the same name as oneanother

is there a way to increment the checkbox name value each time it goes through the while loop in the database?

thx

Link to comment
https://forums.phpfreaks.com/topic/230792-checkboxes-help/
Share on other sites

Use an array:

 

<input type="checkbox" name="eventlist[]">

 

But for these you'll probably want to identify them somehow, maybe with the event ID if there is one:

 

<input type="checkbox" name="eventlist[{id}]">

 

Assuming that {something} are template tags for the PHP vars.

Link to comment
https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1188291
Share on other sites

hmm i was thinkin bout it along that line to use an array but wasnt sure

i think i will use the ID for the identifier for each checkbox

ya ur right its in pear templates

 

if i were to post this page using the form, how would i end up grabin all the checkboxes (checked and unchecked) from the previous page and then insert them accordinly into the db

 

thx

 

Link to comment
https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1188447
Share on other sites

Checkboxes are only posted across if they are actually checked.  The best way to find them is to iterate through the post variables and find any occurences of the checkboxes.

 

THE USER PAGE:

<?php
$sql = "SELECT p_id FROM products;":
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs)){
  extract ($row);
  echo '<input type="checkbox" name="fmCheck_'.$p_id.'" id="fmCheck_'.$p_id.'" value="'.$p_id.'" />';
}
?>

 

PHP PROCESSING PAGE:

<?php
foreach($_POST as $key => $value){
  if (stripos($key,"fmCheck_") !== false){
    $sql = "INSERT INTO products_required VALUES (".$value.");";
    $rs = mysql_query($sql);
  }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1188934
Share on other sites

hmm if i were to post this page using the form, how would i end up grabin all the checkboxes (checked and unchecked) from the previous page and then insert them accordinly into the db

 

with this i can echo the last row for its return back to the page

how can i post only the checked ones into the next page and then save them to the db?

 

Link to comment
https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1192020
Share on other sites

When you use multiple checkboxes then you must use array variable as a name of checkbox,

for example:-

<input type="checkbox" name="formDoor[]" value="A" />Acorn Building<br />
<input type="checkbox" name="formDoor[]" value="B" />Brown Hall<br />
<input type="checkbox" name="formDoor[]" value="C" />Carnegie Complex<br />
<input type="checkbox" name="formDoor[]" value="D" />Drake Commons<br />
<input type="checkbox" name="formDoor[]" value="E" />Elliot House

 

Now the value $_POST[formDoor] is only set when a user checks any of the available checkboxes. And all the selected ones are stored as an array in variable $_POST[formDoor]

Now all you have to do is use foreach and extract every value stored in $_POST[formdoor] :)

Link to comment
https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1192043
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.