user friendly php form processor that includes sticky fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sojo
    New Member
    • May 2007
    • 1

    user friendly php form processor that includes sticky fields

    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
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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($_REQU EST, $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($colorS et as $val => $txt)
    echo "<option value=\"$val\"" . (($_SESSION['REQUEST']['color'] == $val)
    ? ' selected="selec ted"'
    : ''
    ) . ">$txt</option>";
    ?></select>
    [/HTML]

    And so forth.

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      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(iss et($_POST['mytext'])) echo $_POST['mytext'];?>">[/PHP]

      Comment

      Working...