Page 1 of 1
passing actionable info...
Posted: Sun Oct 21, 2007 5:43 pm
by arpowers
Hey guys,
I would like to add a 'delete field' button to a page I am working on...
first thing that comes to mind is using $_GET to pass the info back to the same page. ... self.php?a=delete and then do the required action...
I know this is not recommended.. what is the best way to pass the info?
Posted: Sun Oct 21, 2007 5:50 pm
by gregsometimes
There isn't a "best" way for one specific task in particular. It depends on the context. For example do you want your site to be secure? or does speed of execution matter to you? Anyway, this is just theory.
Have you considered using $_POST instead of $_GET?
You can pass parameters from within a form, with a method="post" in hidden input fields:
<form action="landingpage.php" method="post">
<input type="hidden" name="x" value="1">
</form>
and then picking up with $var = $_POST['x'] on the landing page
For multiple fields, you can have multiple hidden fields, or simply enumerated checkboxes (say with similar names like "delete1", where 1 is the mysql key id number of the field) and scan through them on the landing page with PHP, then parse the values.
example:
Code: Select all
<form action="landingpage.php" method="post">
<input type="checkbox" name="delete_mysqlid71"><br>
<input type="checkbox" name="delete_mysqlid73"><br>
<input type="checkbox" name="delete_mysqlid74"><br>
<input type="checkbox" name="delete_mysqlid75"><br>
<input type="checkbox" name="delete_mysqlid...."><br>
</form>
// so then on the landing page:
$MAXIDS_PER_PAGE=100;
for ($i=0; $i<$MAXIDS_PER_PAGE; $i++) {
$res = "delete_mysqlid".$i;
if ($_POST["$res"] == 'on') {
// delete item number $i
}
}
Hope this makes sense
Posted: Sun Oct 21, 2007 7:31 pm
by s.dot
Yeah, use POST. GET shouldn't be used to perform an action. Say a search engine visits your delete URL and all your content is gone? That's no good.
Posted: Sun Oct 21, 2007 7:41 pm
by Kieran Huggins
I learned that the hard way once
I couldn't understand for the life of me why my records were disappearing!
If you read up on REST design and you'll get a fairly full dose of best practices when dealing with resource mapping.