Page 1 of 1

Form Buttons

Posted: Mon Mar 06, 2006 10:09 pm
by tmaiden
How can I pass a vaule to the same page using a submit button.

Code: Select all

<?
 	....
 	if(isset($_GET['Delete']))
 	{
 		// Delete Row From Table
 	}
 	else
 	{
 		// Display Table With Delete & Reset Buttons
 		...
 		print '<TD>' . $row['id'] . '</TD>';
 		print '<TD><input type="submit" value="Reset"></TD>';
 		print '<TD><input type="submit" value="Delete"></TD></TR>'; 
 		...
 		print "</table></font></form>";
	}
?>


I want to pass "$row['id']" to the IF Statement, so I can delete from a table.

Any suggestions on how I can do this?

Posted: Mon Mar 06, 2006 10:13 pm
by feyd
a form for each row?

Posted: Mon Mar 06, 2006 10:15 pm
by tmaiden
Yes, am I doing it incorrectly?

Posted: Mon Mar 06, 2006 10:16 pm
by tmaiden
Owe wait, no sorry. A form for ALL of the rows.

Posted: Mon Mar 06, 2006 10:20 pm
by tmaiden
I was hoping I could assign the $row['id'] to each button, then pull the id from the button and pass it into my delete query.

Code: Select all

Kinda like
<input type="submit" value="Delete" rowidnumber=$row['id']>

 	if(isset($_GET['Delete']))
 	{
 		// Delete Row From Table
 		$query = "DELETE * FROM table WHERE id = $rowidnumber";
 	}
I know that isn't really possible, but thats what im trying to accomplish.

Posted: Mon Mar 06, 2006 10:26 pm
by Benjamin
Something like this will work, I wrote it based on your quote but it should help you. Modify it to suite your needs.

Code: Select all

<?php
    if(isset($_POST['rowidnumber']))
    {
       // Delete Row From Table
       $query = "DELETE * FROM table WHERE id = $rowidnumber";
    }
?>
<form name="blah" action="" method="post">
<input type="hidden" name="rowidnumber" value="<?php echo $row['id']; ?>" />
<input type="submit" value="Delete">
</form>

Posted: Mon Mar 06, 2006 10:28 pm
by tmaiden
agtlewis, would I have to treat each row as its own form?

Posted: Mon Mar 06, 2006 10:33 pm
by feyd
It would require Javascript, and the page code wouldn't be standards compliant, but that is possible, albeit not exactly like you have it.

If you wish to avoid Javascript, depending on your page design, you can create standards compliant forms for each row that would allow for submission of that rows' data. Now, of course, the page layout is easier to do if you don't care for standards compliance. I'm referring to <form> being inside or outside table rows or cells.

Posted: Mon Mar 06, 2006 10:33 pm
by nickman013
No you can just generate a id for each of the rows, and have a checkbox for each row with the id.

I think.

EDIT: Sample Of What I mean

Code: Select all

<td><input type="checkbox" value="<?php echo $row['ID']; ?>"></td><td><?php echo $row['ID']; ?></td>