Results 1 to 5 of 5

Thread: FMBadHandler should repopulate hidden fields

Threaded View

  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Default FMBadHandler should repopulate hidden fields

    Hi Russell,
    We've recently come across an issue with the FMBadHandler script I hope you'll update in the next version.

    We noticed that the values of hidden fields aren't repopulated into the HTML that the FMBadHandler php file rebuilds after an error message.

    I can imagine why this normally wouldn't be a problem, but here's our need. We're asking students to register for graduation. We're having them log into the form using x.500 authentication, so we can populate the form with some of their PeopleSoft data -- name, email address, student ID, x.500 ID -- and we ask them to provide other information about graduation that isn't in PeopleSoft. Some of the information from the authentication is placed into hidden fields -- partly because it isn't important that they know we are capturing it, but mostly because we don't want them to edit it.

    When the form has an error, FMBadHandler returns all field values in the URL string (including hidden fields), but does not repopluate the hidden fields in the form. We looked at the FMBadHandler script and saw that there wasn't a way to "Fix" hidden fields (although it did "Fix" InputText, Button, TextArea, and Select) -- see script below.

    We had an urgent need to get this working properly so my student worker (computer science major) came up with the solution below. It seems to be working well.

    I wanted to share this with you so that you could see if it (or something similar) was something you wanted to include in future versions of the FMBadHandler script.

    Regards,
    Pete


    ---------------------------------------------------
    Notice at the bottom of fmbadhandler.php there is no method to "Fix" hidden fields.
    ---------------------------------------------------

    {
    if ($bStripData)
    $sValue = StripGPC($sValue);

    //
    // Fix the field if it's an input type "text" or "password".
    //
    $sFormBuf = FixInputText($sName,$sValue,$sFormBuf);
    //
    // Fix the field if it's radio button.
    //
    $sFormBuf = FixButton($sName,$sValue,$sFormBuf);
    //
    // Fix the field if it's a "textarea".
    //
    $sFormBuf = FixTextArea($sName,$sValue,$sFormBuf);
    //
    // Fix the field if it's a "select".
    //
    $sFormBuf = FixSelect($sName,$sValue,$sFormBuf);
    }

    ---------------------------------------------------
    So I've added
    ---------------------------------------------------

    //
    // Fix the field if it's an input type "hidden".
    //
    $sFormBuf = FixHidden($sName,$sValue,$sFormBuf);


    ---------------------------------------------------
    Which refers to the FixHidden function (just a modified FixInputText):
    ---------------------------------------------------

    function FixHidden($s_name,$s_value,$s_buf)
    {
    //
    // we search for:
    // <input type="text" name="thename"...
    // and change it to:
    // <input type="text" name="thename" value="thevalue" ...
    //
    // Note that the value attribute must appear *after* the
    // type and name attributes.
    //

    //
    // first strip any current value attribute for the field
    //

    //
    // (?: ) is a grouping subpattern that does no capturing
    //

    // handle type attribute first
    $s_pat = '/(<\s*input[^>]*type="(hidden)"[^>]*name="';
    $s_pat .= preg_quote($s_name,"/");
    $s_pat .= '"[^>]*)(value="[^"]*")([^>]*?)(\s*\/\s*)?>';
    $s_pat .= '/ims';
    $s_buf = preg_replace($s_pat,'$1$3$4>',$s_buf);

    // handle name attribute first
    $s_pat = '/(<\s*input[^>]*name="';
    $s_pat .= preg_quote($s_name,"/");
    $s_pat .= '"[^>]*type="(hidden)"[^>]*)(value="[^"]*")([^>]*?)(\s*\/\s*)?>';
    $s_pat .= '/ims';
    $s_buf = preg_replace($s_pat,'$1$3$4>',$s_buf);

    //
    // now add in the new value
    //
    $s_repl = '$1 value="'.htmlspecialchars($s_value).'" $2>';

    // handle type attribute first
    $s_pat = '/(<\s*input[^>]*type="(hidden)"[^>]*name="';
    $s_pat .= preg_quote($s_name,"/");
    $s_pat .= '"[^>]*?)(\s*\/\s*)?>';
    $s_pat .= '/ims';
    $s_buf = preg_replace($s_pat,$s_repl,$s_buf);

    // handle name attribute first
    $s_pat = '/(<\s*input[^>]*name="';
    $s_pat .= preg_quote($s_name,"/");
    $s_pat .= '"[^>]*type="(hidden)"[^>]*?)(\s*\/\s*)?>';
    $s_pat .= '/ims';
    $s_buf = preg_replace($s_pat,$s_repl,$s_buf);

    return ($s_buf);
    }
    Last edited by priemen; 08-Mar-2010 at 06:18 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Date in hidden field and results email
    By ewel in forum FormMail Subscription Support
    Replies: 3
    Last Post: 07-Feb-2006, 12:00 PM
  2. Some fields not remembered using fmbadhandler
    By penta5 in forum FormMail Subscription Support
    Replies: 1
    Last Post: 12-Oct-2005, 10:35 PM
  3. My hidden fields are not hidden at all!
    By mikie in forum FormMail Subscription Support
    Replies: 1
    Last Post: 04-Jul-2005, 08:26 PM
  4. I need a hidden form that [BACk] won't retrigger
    By NOgbourne in forum FormMail Subscription Support
    Replies: 2
    Last Post: 04-Jan-2005, 09:17 PM
  5. Deriving fields from other fields
    By russellr in forum HOWTO Guides and Tips
    Replies: 0
    Last Post: 13-May-2004, 12:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •