Reply to Re: Approving Items

Your name:

Reply:


Posted by Jerry Stuckle on 10/22/06 18:11

Pedro Graca wrote:
> James54321 wrote:
>
>>I have recently set up most of my new site in PHP which i'm very happy
>>about but now i have hit a problem. I am now at the stage of making
>>admin's lives easier by making it so they can use a nice interface and
>>not phpMyAdmin to aurhorise submisions to the site.
>>
>>I have created a page whereby the yet to be authenticated submitions
>>are shown to the admin with three radio boxes next to each submition
>>one to ban the user (ip address of) one to approve the submision and
>>the other is to delete the submition. I also have a button which
>>submits the form to itself.
>>
>>But now I need to know how to process that as I dont know how to do a
>>loop that chceks what the radio option is and takes the appropriate
>>action. Because an admin could leave an option that must also be
>>allowed for as they may need to ask another admin about it so it could
>>be id 50, 54, 55, 56, 57, 60 etc and I dont know how to allow for that.
>>
>>So if any of you could please help me with this matter I wouold really
>>appreciate it.
>>
>>P.S.
>>
>>To allow a comment the "approved" field has to be set to 1 instead of 2
>>and to delete it gets erased from the whole db and ban would put the ip
>>of the user into another ban list db.
>>
>>But I can do that code, I just need the loop part and if possible that
>>if statement.
>>
>>Oh and btw the options are named by the id of the submition ... but
>>this can be changed if necessary.
>
>
> Without you showing your code and HTML it's a bit hard to help you.
>
> Here's an HTML file
>
> <html>
> <head><title>title</title></head>
> <body>
> <form action="" method="post">
> submission 1
> <label><input type="checkbox" name="id1" value="0" checked>No change</label>
> <label><input type="checkbox" name="id1" value="1">Ban</label>
> <label><input type="checkbox" name="id1" value="2">Approve</label>
> <label><input type="checkbox" name="id1" value="3">Delete</label>
> <br>
> submission 42
> <label><input type="checkbox" name="id42" value="0" checked>No change</label>
> <label><input type="checkbox" name="id42" value="1">Ban</label>
> <label><input type="checkbox" name="id42" value="2">Approve</label>
> <label><input type="checkbox" name="id42" value="3">Delete</label>
> <br>
> <input type="submit">
> </form>
> </body>
> </html>
>
> When the server receives this form it will have $_POST['id1'] and
> $_POST['id42'] set to one of 0, 1, 2, or 3 (unless the client chose to
> lie to the server).
> You can check the keys and values with
>
> <?php
> foreach ($_POST as $key=>$value) {
> if (preg_match('/^id(\d+)$/', $key, $mat)) {
> switch ((int)$value) {
> case 0: /* void */ break;
> case 1: submission_ban($mat[1]); break;
> case 2: submission_approve($mat[1]); break;
> case 3: submission_delete($mat[1]); break;
> default: /* client is lying */ break;
> }
> }
> }
> ?>
>
> Happy Coding :)

One change I would make to this:

<label><input type="checkbox" name="id[42]" value="1">Ban</label>

etc.

Notice the 42 is a subscript. Then you can do things like:

$id = $_POST['id']'
foreach ($id as $key=>$value) {
// No pregmatch needed



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация