Page 1 of 1
semi-advanced forms
Posted: Wed Jun 27, 2007 1:12 pm
by mabufo
I want to have a page for managing database entries. It's easy enough to list the entries, and to delete them one at a time... but what I would like to do is output all of the entries in my 'quotes' table, and have the user select which ones need to be deleted (the user should be able to somehow check them off, and then be able to click 'delete selected'). How do I do this sort of thing? I have an idea about how this is done, it's just the implementation that is throwing me off, could anyone show me - or point me in the direction of a tutorial that could? Also, say I want to edit an entry... is it possible to get my php script to load the item of data in a textbox with a sort of submit button next to it? Once again, querying the database for the info is doable for me - it takes like 5 seconds of looking at the documentation for that one, but it's the practical application of this sort of form trickery that I have to learn by example.
Anything other than text input in forms is something I don't know how to do.
Thanks again.
Posted: Wed Jun 27, 2007 1:55 pm
by RobertGonzalez
Think checkboxes and arrays, then search for form handling and multiple inputs.
Posted: Wed Jun 27, 2007 4:25 pm
by mabufo
Thanks, I'm not really on board with the terminology.
Posted: Wed Jun 27, 2007 4:28 pm
by patrikG
Posted: Wed Jun 27, 2007 4:49 pm
by RobertGonzalez
Sometimes trying something can be worth a ton...
Code: Select all
<?php
if (!empty($_POST))
{
echo '<pre>'; var_dump($_POST); echo '</pre>';
}
?>
<form action="<?php echo basename(__FILE__); ?>" method="post">
<input type="checkbox" name="check[]" value="1" checked="checked" />Check 1<br />
<input type="checkbox" name="check[]" value="2" />Check 2<br />
<input type="checkbox" name="check[]" value="3" checked="checked" />Check 3<br />
<input type="checkbox" name="check[]" value="4" />Check 4<br />
<input type="submit" name="submit" value="Send Test" />
</form>
Posted: Wed Jun 27, 2007 5:14 pm
by mabufo
Much appreciated. For me, it's just easier to learn by example. With what you posted, if I understand, the array is filled with the name of whatever was checked off(the button's 'value'), and from there I can iterate through the array and deal with each element(form value).
I think I get it, and that greatly helps.
EDIT: I'll be sure to post what I have when I'm finished so people can see a cool working example.
Posted: Wed Jun 27, 2007 5:17 pm
by RobertGonzalez
You got it.