PHP - passing a variable from a repeated region?
Moderator: General Moderators
PHP - passing a variable from a repeated region?
Hello,
I am having trouble with submitting a row from a repeat region. Each row of the repeat region contains 'ID' and a 'Submit' checkbox.
Repeated Region
------------------------------------------------
{Recordset1.ID}-hidden, {Recordset1.notes} | SUBMIT |
------------------------------------------------
On my page I see a list of notes and each one has it's own submit checkbox that should be removed when done(checked off). My problem it that it does not matter what checkbox is selected, it only removes the last entry in the list (submits the last row's ID).
Now what I need to do is on Submit pass the specific ID of the row in the table for which the submit was triggered.
For example if they scroll down to the 5 element in the repeated region (with ID 5) and they hit Submit I need to pass the number 5 to a function.
Does anyone know how I can do this properly?
Any help would be appreciated!
I am having trouble with submitting a row from a repeat region. Each row of the repeat region contains 'ID' and a 'Submit' checkbox.
Repeated Region
------------------------------------------------
{Recordset1.ID}-hidden, {Recordset1.notes} | SUBMIT |
------------------------------------------------
On my page I see a list of notes and each one has it's own submit checkbox that should be removed when done(checked off). My problem it that it does not matter what checkbox is selected, it only removes the last entry in the list (submits the last row's ID).
Now what I need to do is on Submit pass the specific ID of the row in the table for which the submit was triggered.
For example if they scroll down to the 5 element in the repeated region (with ID 5) and they hit Submit I need to pass the number 5 to a function.
Does anyone know how I can do this properly?
Any help would be appreciated!
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP - passing a variable from a repeated region?
Show your form and state exactly what you want to happen when what is clicked.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: PHP - passing a variable from a repeated region?
Here is the code for the form.
Here is the php code.
The problem is with the line:
GetSQLValueString($_POST['equ_hr_id'], "int"));
this returns the current 'equ_hr_id' for the FORM, which is from the last repeated row. I want it to submit the $row_rsForemanNotes['equ_hr_id'] when the checkbox for it's row is checked. The page then would refresh without the checked note.
Thanks
Code: Select all
<form action="<?php echo $editFormAction; ?>" id="form2" name="form2" method="POST">
<p> </p>
<table>
<tr class="tRow">
<td>Repaired:</td>
<td>Foreman Notes:</td>
</tr>
<?php do { ?>
<tr>
<td><input name="equ_hr_id" type="hidden" id="equ_hr_id" value="<?php echo $row_rsForemanNotes['equ_hr_id']; ?>" /><?php echo $row_rsForemanNotes['equ_hr_id']; ?>
<input name="notes_closed" type="checkbox" id="notes_closed" value="" onmouseup="form2.submit()" /></td>
<td><?php echo $row_rsForemanNotes['notes']; ?></td>
</tr>
<?php } while ($row_rsForemanNotes = mysql_fetch_assoc($rsForemanNotes));?>
</table>
<input type="hidden" name="MM_update" value="form2" />
</form>Here is the php code.
Code: Select all
<?php
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE equ_hours SET notes_closed=%s WHERE equ_hr_id=%s",
GetSQLValueString(isset($_POST['notes_closed']) ? "true" : "", "defined","1","1"),
GetSQLValueString($_POST['equ_hr_id'], "int"));
mysql_select_db($database_earth_iron, $earth_iron);
$Result1 = mysql_query($updateSQL, $earth_iron) or die(mysql_error());
}
?>Code: Select all
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE equ_hours SET notes_closed=%s WHERE equ_hr_id=%s",
GetSQLValueString(isset($_POST['notes_closed']) ? "true" : "", "defined","1","1"),
GetSQLValueString($_POST['equ_hr_id'], "int"));
mysql_select_db($database_earth_iron, $earth_iron);
$Result1 = mysql_query($updateSQL, $earth_iron) or die(mysql_error());
}The problem is with the line:
GetSQLValueString($_POST['equ_hr_id'], "int"));
this returns the current 'equ_hr_id' for the FORM, which is from the last repeated row. I want it to submit the $row_rsForemanNotes['equ_hr_id'] when the checkbox for it's row is checked. The page then would refresh without the checked note.
Thanks
Last edited by cshaw on Tue Mar 30, 2010 2:16 pm, edited 2 times in total.
Re: PHP - passing a variable from a repeated region?
Please edit your post and add code tags.
Re: PHP - passing a variable from a repeated region?
I did edit the code. My '('s throughout are being replaced though. Can I get around this?
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP - passing a variable from a repeated region?
Just use your equ_hr_id as the value for the checkbox:
Then:
Code: Select all
<input name="notes_closed" type="checkbox" id="notes_closed" value="<?php echo $row_rsForemanNotes['equ_hr_id']; ?>" onmouseup="form2.submit()" />Code: Select all
GetSQLValueString($_POST['notes_closed'], "int"));mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: PHP - passing a variable from a repeated region?
I tried the idea of attaching th equ_hr_id to the checkbox instead of a seperate hidden field in the row. Still not working though. Now it is not returning a value at all. I will go through my code to make sure I'm not missing anything.
Thanks for the help so far.
Thanks for the help so far.
Re: PHP - passing a variable from a repeated region?
This solution does not work. onmouseup"submit.form2" triggers the form to submit, but not the values from the checkbox itself. It submits the last updated values from the form as a whole.
1. I need for the update section to pull the ROW Variable from the form instead of taking the last row value the form gives it.
2. or the form has to ruturn the value from the repeat region ROW according to which checkbox was checked that triggered the submit command.
Thanks,
1. I need for the update section to pull the ROW Variable from the form instead of taking the last row value the form gives it.
2. or the form has to ruturn the value from the repeat region ROW according to which checkbox was checked that triggered the submit command.
Thanks,
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP - passing a variable from a repeated region?
Then you probably need to try onchange instead of onmouseup I would assume. It's kind of odd what you're doing so it's hard to pin down the issue.cshaw wrote:This solution does not work. onmouseup"submit.form2" triggers the form to submit, but not the values from the checkbox itself. It submits the last updated values from the form as a whole.
1. I need for the update section to pull the ROW Variable from the form instead of taking the last row value the form gives it.
2. or the form has to ruturn the value from the repeat region ROW according to which checkbox was checked that triggered the submit command.
Thanks,
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP - passing a variable from a repeated region?
And I assume you want to change this:
To this:
If you haven't already.
Code: Select all
GetSQLValueString($_POST['equ_hr_id'], "int"));Code: Select all
GetSQLValueString($_POST['notes_closed'], "int"));mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: PHP - passing a variable from a repeated region?
Yes I did try eveything you suggested as well as onchange. Nothing seems to work.
Is this task really that difficult?
I am trying to display a list of tasks in a form with a repeat region. Within the form I would like to check off the tasks that were accomplished and then have those checked tasks update the appropriate row when the whole form is submitted. I read that I cannot update multiple entries with one submit, so I broke out this portion and am trying to have the form just update the single row that I select with the checkbox.
Is there a better way to structure this task? What is the best way to create a task list that can be checked off in any order?
Thanks again,
Is this task really that difficult?
I am trying to display a list of tasks in a form with a repeat region. Within the form I would like to check off the tasks that were accomplished and then have those checked tasks update the appropriate row when the whole form is submitted. I read that I cannot update multiple entries with one submit, so I broke out this portion and am trying to have the form just update the single row that I select with the checkbox.
Is there a better way to structure this task? What is the best way to create a task list that can be checked off in any order?
Thanks again,
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP - passing a variable from a repeated region?
It is actually easy to do what you describe. With the onmouseup submit it would be assumed that you wanted the form submitted when any checkbox was clicked. I'll post something later, or search my posts for checkbox, I think I've answered several of these.cshaw wrote:Yes I did try eveything you suggested as well as onchange. Nothing seems to work.
Is this task really that difficult?
I am trying to display a list of tasks in a form with a repeat region. Within the form I would like to check off the tasks that were accomplished and then have those checked tasks update the appropriate row when the whole form is submitted. I read that I cannot update multiple entries with one submit, so I broke out this portion and am trying to have the form just update the single row that I select with the checkbox.
Is there a better way to structure this task? What is the best way to create a task list that can be checked off in any order?
Thanks again,
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: PHP - passing a variable from a repeated region?
I did search your posts and did not find anything I can use.
Thank you for the help. I will wait for your post.
Thank you for the help. I will wait for your post.
Re: PHP - passing a variable from a repeated region?
Am not sure if am understanding this but am gona break it down and see if i understood.
1. You have an extract from the database into a form with a series of checkbox.
2. If you check a checkbox it marks the note as closed.
3. Also when checked the page refreshes and that note get removed (I guess you've already taken care of that)
4. Your problem is that now its not working as when you submit this only the last value gets updated
Did i get this right??
Now if i did here's a couple of suggestion
1. Change the name of your checkbox notes_closed to notes_closed[]
2. Set the value in this checkbox to the id i.e. value="<?php echo $row_rsForemanNotes['equ_hr_id']; ?>"
3. In your update section do this after this line
ADD this
4. In your query $updateSQL change this
to this
I thinks this should do the trick. When using repeated region you need to work with arrays most of the time. so by adding squarebrackets []
notes_closed am making this form field an array. And then using foreach is extract each values in notes_closed into value concatenate it with a comma ,
then using rtrim i remove the extra , and the job is done.
I haven't tested it but in theory this should work.
1. You have an extract from the database into a form with a series of checkbox.
2. If you check a checkbox it marks the note as closed.
3. Also when checked the page refreshes and that note get removed (I guess you've already taken care of that)
4. Your problem is that now its not working as when you submit this only the last value gets updated
Did i get this right??
Now if i did here's a couple of suggestion
1. Change the name of your checkbox notes_closed to notes_closed[]
2. Set the value in this checkbox to the id i.e. value="<?php echo $row_rsForemanNotes['equ_hr_id']; ?>"
3. In your update section do this after this line
Code: Select all
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {Code: Select all
foreach($_POST['notes_closed'] as $value)
{
$id.=$value.",";
}
Code: Select all
GetSQLValueString($_POST['equ_hr_id'], "int")Code: Select all
GetSQLValueString(rtrim($id,","), "text")
notes_closed am making this form field an array. And then using foreach is extract each values in notes_closed into value concatenate it with a comma ,
then using rtrim i remove the extra , and the job is done.
I haven't tested it but in theory this should work.
Re: PHP - passing a variable from a repeated region?
This makes sense and hopefully will work soon.
I am getting an error: Invalid argument supplied for foreach()
Here is what I have now for update. Do you see where I have gone wrong?
I am getting an error: Invalid argument supplied for foreach()
Here is what I have now for update. Do you see where I have gone wrong?
Code: Select all
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
foreach($_POST['notes_closed'] as $value)
{
$id.=$value.",";
}
$updateSQL = sprintf("UPDATE equ_hours SET notes_closed=%s WHERE equ_hr_id=%s",
GetSQLValueString(isset($_POST['notes_closed']) ? "true" : "", "defined","1","1"),
GetSQLValueString(rtrim($id,","), "text"));
mysql_select_db($database_earth_iron, $earth_iron);
$Result1 = mysql_query($updateSQL, $earth_iron) or die(mysql_error());
}