Help on recordset and checkboxes
Moderator: General Moderators
Help on recordset and checkboxes
Hi,
I have the following recordset that outputs a list of values from a recordset long with a checkbox next to each one as follows:
fieldaValue1 fieldbValue1 checkbox1
fieldaValue2 fieldbValue2 checkbox2
and so on....
the code I have is this:
?php echo $row_Recordset1['PDF_KEY_PRODUCT'];
$i = 1 + $varincrement;
$varincrement = $i++;
?>
</td>
<td width="150"><?php echo $row_Recordset1['PDF_LONG_DESCRIPTION']; ?></td>
<td width="50"> </td>
<td width="50"><?php echo $row_Recordset1['PDF_SELLING_PRICE']; ?></td>
<td width="50"><input name="textfield" type="text" size="5"></td>
<td width="50"><?php echo "<input type=\"checkbox\" name=\"checkbox$varincrement\" value=\"checkbox\"></td>";?>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
I use an increment operator to produce new names for each checkbox in the recordset,
My problem is this: I want to let the user click on different checkboxes and then submit only the values rows where a checkbox is checked to another script,
does anyone have any ides how to do this??
thanks a lot
I have the following recordset that outputs a list of values from a recordset long with a checkbox next to each one as follows:
fieldaValue1 fieldbValue1 checkbox1
fieldaValue2 fieldbValue2 checkbox2
and so on....
the code I have is this:
?php echo $row_Recordset1['PDF_KEY_PRODUCT'];
$i = 1 + $varincrement;
$varincrement = $i++;
?>
</td>
<td width="150"><?php echo $row_Recordset1['PDF_LONG_DESCRIPTION']; ?></td>
<td width="50"> </td>
<td width="50"><?php echo $row_Recordset1['PDF_SELLING_PRICE']; ?></td>
<td width="50"><input name="textfield" type="text" size="5"></td>
<td width="50"><?php echo "<input type=\"checkbox\" name=\"checkbox$varincrement\" value=\"checkbox\"></td>";?>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
I use an increment operator to produce new names for each checkbox in the recordset,
My problem is this: I want to let the user click on different checkboxes and then submit only the values rows where a checkbox is checked to another script,
does anyone have any ides how to do this??
thanks a lot
I don't think that is possible. Let hear a javascript guru comment on this (onclick/onsubmit issue?).... and then submit only the values rows where a checkbox is checked
What exactly do you mean by 'rows'?
Code: Select all
<!-- result:
Array
(
[checkbox1] => 1
[checkbox3] => 3
[checkbox5] => 5
[checkbox7] => 7
[checkbox9] => 9
[checkbox11] => 11
[checkbox13] => 13
[checkbox15] => 15
[checkbox17] => 17
[checkbox19] => 19
)
-->
<pre>
<form method="post">
<?php
for ($i=1;$i<=20;$i++) {
$status = ($i % 2 ? ' checked' : '');
echo '<input type="checkbox" name="checkbox'.$i.'" value="'.$i.'"'.$status.' />';
}
?>
<input type="submit" />
</form>
<?php
print_r($_POST);
?>
</pre>Hi
thanks for reply
by rows, I mean each row in database, i.e. fieldaValue1 fieldbValue2 but I may be thinking about that the wrong way.
Anyway I have this code from another forum, but dont fully understand it:
<form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="input_one">
<input type="checkbox" name="check_one"><br>
<input type="text" name="input_two">
<input type="checkbox" name="check_two"><br>
<input type="submit" name="submit" value="Go"></p>
</form>
<?PHP
if (isset($_POST['submit'])) {
$matches = array();
foreach ($_POST as $name => $value) {
if (preg_match("/^check_(w+)/", $name, $match)) {
$matches[] = "input_".$match[1];
}
}
foreach ($matches as $field) {
echo $_POST[$field]."<br>";
}
}
?>
looks like using the preg_match to check if a check box is checked but dont get this.
Whats oes your code do? It uses javascript to put values into arrays then sends to php?
by rows, I mean each row in database, i.e. fieldaValue1 fieldbValue2 but I may be thinking about that the wrong way.
Anyway I have this code from another forum, but dont fully understand it:
<form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="input_one">
<input type="checkbox" name="check_one"><br>
<input type="text" name="input_two">
<input type="checkbox" name="check_two"><br>
<input type="submit" name="submit" value="Go"></p>
</form>
<?PHP
if (isset($_POST['submit'])) {
$matches = array();
foreach ($_POST as $name => $value) {
if (preg_match("/^check_(w+)/", $name, $match)) {
$matches[] = "input_".$match[1];
}
}
foreach ($matches as $field) {
echo $_POST[$field]."<br>";
}
}
?>
looks like using the preg_match to check if a check box is checked but dont get this.
Whats oes your code do? It uses javascript to put values into arrays then sends to php?
Not sure if I've got my head round you're full procedure here but, as far as submitting ONLY the checked values, that's the normal behaviour.
If you have checkboxes with html input field name attributes like:
name="options[1]"
name="options[2]"
name="options[3]"
..on submission of the form, $_POST['options'] will be an array containing just the checked boxes.
If none were checked $_POST['options'] will not be set.
If you have checkboxes with html input field name attributes like:
name="options[1]"
name="options[2]"
name="options[3]"
..on submission of the form, $_POST['options'] will be an array containing just the checked boxes.
If none were checked $_POST['options'] will not be set.
Hi
OK ignore that code with the two textfields
I have a recordset that outputs three columns and then a checkbox. I know how to dynamically rename the checkbox name and value if that is necessary.
When the user presses submit I only want to submit the rows of collumn data where the user has clicked on the coressponding checkbox. Now I know that only values from checked boxes will submit, but as it is none of the column data will submit because it is not in a hidden field or any other form component. I want to know the best way to submit this data. Either to submit only the checked data, or submit everything and then somehow compare these values to the submitted checkbox value so that I end up with only checked rows.
I have thought abut hidden field. Also I thought about concatenating te three column values and setting the value of the checkbox to this concatenated value,
any ideas?
I have a recordset that outputs three columns and then a checkbox. I know how to dynamically rename the checkbox name and value if that is necessary.
When the user presses submit I only want to submit the rows of collumn data where the user has clicked on the coressponding checkbox. Now I know that only values from checked boxes will submit, but as it is none of the column data will submit because it is not in a hidden field or any other form component. I want to know the best way to submit this data. Either to submit only the checked data, or submit everything and then somehow compare these values to the submitted checkbox value so that I end up with only checked rows.
I have thought abut hidden field. Also I thought about concatenating te three column values and setting the value of the checkbox to this concatenated value,
any ideas?
Still not quite sure if I get it. Is this a form you use to edit data stored in a db?
If so, you don't need checkboxes at all.
(1) Set a value="<?php echo $field_value; ?>" attribute in the form input fields (you've got name and type but no preset values).
(2) When the form is submitted, update the db with the values returned in the POST array.
I'm sure there is a simple solution to this once I understand exactly what you're doing.
If so, you don't need checkboxes at all.
(1) Set a value="<?php echo $field_value; ?>" attribute in the form input fields (you've got name and type but no preset values).
(2) When the form is submitted, update the db with the values returned in the POST array.
I'm sure there is a simple solution to this once I understand exactly what you're doing.