Using mysql database and procedural code.
I'm considering, on initial page load, pre-populating $_POST(ed) values like so (error checking, etc left out for clarity):
$result = $db->query("select foo, bar from baz ...");
list($_POST['foo'], $_POST['bar']) = $result->fetch_row();
And set the initial page load form values like this:
<input name="foo" value="<?php echo $_POST['foo'] ?>"...>
This way the form values are already initiated upon failed server side validation. I eliminate database access until I'm ready to insert or update the table.
I should note that upon every page initialization, if a $_POST array exists, it's session id value (in a hidden input) is checked against the current session id for validation. Sessions values are stored in a database.
I can't see any reason not to start using this logic, but would like some input form other developers.
Aucun commentaire:
Enregistrer un commentaire