You are here: Re: Avoid 'GET' method « PHP Programming Language « IT news, forums, messages
Re: Avoid 'GET' method

Posted by Umberto Salsi on 07/19/05 06:12

gordonb.qy408@burditt.org (Gordon Burditt) wrote:

> I'd be interested in someone's idea for a solution to the general
> problem: you have a table with possibly hundreds or thousands of
> lines in it.

$button_n = 0;

function Button($text, $action)
{
global $button_n;
echo "<input type=submit name=button_", $button_n, " value=$text>";
echo "<input type=hidden name=action_", $button_n, " value=",
base64encode( serialize( $action ) ), ">";
/* optional: add an hidden field with the MAC of the serialized
$action, to be checked later on submit */
$button_n++;
}

/* Generate the form: */

for( every row of the table ){
echo "<form ...>";
echo "...the record...";
Button("Edit", array( "op" => EDIT, "record" => 1234 ));
Button("Remove", array( "op" => REMOVE, "record" => 1234 ));
/* ...and so on for every button */
echo "</form>";
}

.....

/* Handle the POST: */

$n = examine $_POST looking for the number of the parameter
named "^button_[0-9]+$";
$action = unserialize( base64decode( $_POST['action_' . $n] ) );
-- do the action given by $action

Hint: all those hidden fields may conveniently be stored in the user session.
Hint 2: the "$action" may contain the name and the arguments of a function
to call, so that with Button() we set a "call-back". In this case, better
to use the session, or the MAC is mandatory to prevent tampering.

Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

 

Navigation:

[Reply to this 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

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