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?
passing actionable info...
Moderator: General Moderators
- gregsometimes
- Forum Newbie
- Posts: 11
- Joined: Sun Oct 21, 2007 1:57 pm
- Location: San Francisco, CA
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:
Hope this makes sense
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
}
}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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact: