NYCPHP Meetup

NYPHP.org

[nycphp-talk] Managing form data with PHP

Jake McGraw jmcgraw1 at gmail.com
Tue Dec 11 14:03:51 EST 2007


Smarty, Smarty, Smarty. smarty.php.net.

Smarty Template File:

Error "log" at the top of the page could look like this:
<ul class="errors">
{foreach from=$errors key=field item=message}
  <li class="{$message.severity|default:low}">{$field} :
{$message.text}</li>
{/foreach}
</ul>

Each field label could be marked up to include the above error:
<label for="fullname"{if $error.fullname} class="error"{/if}>Full
Name:</label>
<input type="text" name="fullname" id="fullname"
value="{$smarty.post.fullname|filter_var:$smarty.const.FILTER_SANITIZE_STRING}"/>

Note that the whole filter_var thing could be looped inside of your PHP
script, I just included it because you should always cleanout POST and GET
and REQUEST.

- jake


On Dec 11, 2007 1:47 PM, John Campbell <jcampbell1 at gmail.com> wrote:

> > The 'pretty' enhancements are relatively easy - but I'm having a
> > problem trying to get the form data to redisplay.
>
> Start by submitting the form to the script that renders the page:
> <form action="" method="post">
> Then each field should of the form:
> <input type="text" name="username" value="<?php echo
> htmlspecialchars($_POST['username']); ?>" />
>
> If the post data is valid, redirect.  Otherwise, the form will
> automatically redisplay with the original values intact.
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20071211/4fa83ffd/attachment.html>


More information about the talk mailing list