Re: [SMARTY] Default variable values for forms

From: Date: Sun, 23 Jun 2002 15:38:19 +0000
Subject: Re: [SMARTY] Default variable values for forms
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4976@lists.php.net to get a copy of this message
> Date: Sat, 22 Jun 2002 15:25:34 +0200 > From: Lech Rychliński <l.rychlinski@w3crew.com.pl> > To: smarty-general@lists.php.net > Subject: [SMARTY] Default variable values for forms > I've a line from my form like this: > > <input type="text" name="name" value={$post.name}> > > and in my php file sth like this: > > if ($method == 'POST') > $tpl -> assign('post', $_POST); > > everything is ok when I'm parsing submited form, problems appears when > the method is GET. then in my input field i've got 'Undefined index: > name' > > manual says that i can do sth like this: > > <input type="text" name="name" > value={$post.name|default:"&nbsp;"}> > > but in fact it doesn't change anything because I see error about name > index again. i've tried even sth like this: > > {assign var="name" value=$post.name|default:"nothing"} > <input type="text" name="name" value={$name}> > > no effect. > > so my question is how to put posted values into form if i need to > reedit sth and do not generate errors when sth is missing. Hi there. Are you running with error_reporting = E_ALL? ISTR seeing this happen with that level, but can't reproduce it now. :( Anyway, what I do is this: function getFormData($var, $default = null) { if (isset($_POST[$var])) return $_POST[$var]; if (isset($_GET[$var])) return $_GET[$var]; return $default; } $vars = array('foo', 'bar', 'baz'); $FORM = array(); foreach ($vars as $v) $FORM[$v] = getFormData($v, ''); $t->assign('FORM', $FORM); -- FreeBSD 4.5-STABLE 5:26PM up 20 days, 7:15, 12 users, load averages: 0.00, 0.00, 0.00

« previous php.smarty.general (#4976) next »