3 functions for easier pog operations

0 views
Skip to first unread message

pibot

unread,
Apr 16, 2008, 2:45:40 PM4/16/08
to Php Object Generator
Hi folks,
with this 3 functions its very easy to do the simple pog operations,
what you need to do is to name the tablefields in the Database similar
to the formfields. I have this code in my submit.php, for security
reasons i allow only files on my domain to execute the submit.php


function pog_new($object,$exclude_array){

if($_SERVER['REQUEST_METHOD'] == 'POST') {
foreach($_POST as $key=>$value) {
if (!(in_array($key,$exclude_array)))
{
$object->$key=$value;
}
}
$object->Save();
}
}

function pog_change($object,$id,$exclude_array){
$object->Get($id);
if($_SERVER['REQUEST_METHOD'] == 'POST') {
foreach($_POST as $key=>$value) {
if (!(in_array($key,$exclude_array)))
{
$object->$key=$value;
}
}
$object->Save();
}
}
function pog_del($object,$id){
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$object->Get($id);
$object->Delete();
}
}

// for example to add a new record
// pog_new(new newsletter,array('senden','id'));
// senden' and 'id' will be excluded, all other $_Post Variables will
be written, if there is a tablefield in the Database with the same
name.

tell me please what you think about it and if you have any questions
or suggestions

andy law (RI)

unread,
Apr 17, 2008, 6:21:01 AM4/17/08
to Php-Object...@googlegroups.com
I have something similar as part of a more extensive - but still
incomplete after 18 months of 'spare' time working on it in the evenings
- package of form handling utilities.

I would suggest that it would be safer to explicitly specify fields to
include rather than assuming inclusion unless excluded.

Later,

Andy

-------------
Yada, yada, yada...

Roslin Institute is a company limited by guarantee, registered in
Scotland (registered number SC157100) and a Scottish Charity (registered
number SC023592). Our registered office is at Roslin, Midlothian, EH25
9PS. VAT registration number 847380013.

The information contained in this e-mail (including any attachments) is
confidential and is intended for the use of the addressee only. The
opinions expressed within this e-mail (including any attachments) are
the opinions of the sender and do not necessarily constitute those of
Roslin Institute (Edinburgh) ("the Institute") unless specifically
stated by a sender who is duly authorised to do so on behalf of the
Institute.

Reply all
Reply to author
Forward
0 new messages