By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

user friendly php form processor that includes sticky fields

P: 1
As a web designer with only very rudimentary php skills, I've looked all over for a user friendly php form processor that includes sticky fields. The best match for my needs, php form wizard (http://tools4php.com/form-wizard/), lacks only the sticky field functionality. If useability is a priority, this functionality is essential for long forms with several fields to validate.

I'm partial to this app because I've already created the rather large form.

Any insights would be so much appreciated ... tia

sojo
May 11 '07 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
By 'sticky field', I assume you mean that the User's input is saved between page loads (so, for example, he doesn't lose any input if you need to report an error or a validation warning).

Smarty is pretty good at this, but it's probably too late in the app's development cycle to try to start implementing a template system.

It's somewhat difficult with selects and checkboxes, but for text inputs, it's pretty easy to keep track of the value.

First thing you'll probably want to do is save the [VALIDATED!] input to the User's session.

Something like this (I'm pulling relevant code from my frameworks and trying to simplify it for the context; bear with me):
[PHP]
// Set up default values.
if(! isset($_SESSION['REQUEST']))
$_SESSION['REQUEST'] = array(
'flavor' => 'Brownie Batter',
'color' => 'purple',
etc.
);

$blacklist = array(
'PHPSESSID' => true,
'USERNAME' => true,
'PASSWORD' => true,
'LOGOUT' => true
);
// Overwrite $_SESSION['REQUEST'] with NEW values only.
$_SESSION['REQUEST'] = array_merge(
$_SESSION['REQUEST'],
validate(array_diff_key($_REQUEST, $blacklist))
);
[/PHP]

Note that 'validate' is a placeholder; replace it with your favorite validation function or object.

Now that you've got a persistent $_SESSION['REQUEST'], you can output it fairly easily.

[HTML]
<input name="flavor" type="text" value="<?php echo $_SESSION['REQUEST']['flavor']; ?>" />

<select name="color"><?php
foreach($colorSet as $val => $txt)
echo "<option value=\"$val\"" . (($_SESSION['REQUEST']['color'] == $val)
? ' selected="selected"'
: ''
) . ">$txt</option>";
?></select>
[/HTML]

And so forth.
May 11 '07 #2

code green
Expert 100+
P: 1,726
If you don't want to use sessions. You can bury php inside the HTML tag. i don't like it, but it works OK [PHP]<input type="text" name="mytext"
value="<?if(isset($_POST['mytext'])) echo $_POST['mytext'];?>">[/PHP]
May 11 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.