Results 1 to 5 of 5

Thread: FMBadHandler should repopulate hidden fields

Hybrid 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.

  2. #2
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: FMBadHandler should repopulate hidden fields

    Hi,

    Thanks for your feedback on this issue.

    The main problem with replacing hidden field values comes when you have a multi-page form.

    In the case of multi-page forms, replacing hidden field values would actually break the processing because you also use hidden fields to control FormMail's operation.

    This *could* be a problem in a single page form too, if FormMail altered a special field value before calling FMBadHandler.

    So, there's no guarantee that this will keep working in the future.

    I understand exactly why you need this to happen for your application of FormMail.

    We're planning to re-visit the error handling features of FormMail later this year, so we'll make sure we note down your requirement as part of this development.

    I think the safest solution would be to allow form designers to specify an *additional* list of fields to be re-entered during error handling (so, you'd list the hidden fields you want re-entered).

    BTW, another way you could have solved the problem (without code changes) would be to load them as text fields instead of hidden fields, and then put them all in a hidden <div> section (i.e. hidden using CSS or similar).

    FMBadHandler would replace their values because they were normal fields as far as it was concerned, but the user wouldn't see them.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Jan 2010
    Posts
    2

    Default Re: FMBadHandler should repopulate hidden fields

    Thanks for the reply. And thanks for the suggestion about the hidden DIVs - that should work equally well, without the potential of breaking the script in ways we can't anticipate.

    As always, thanks for taking our feedback into consideration and for continuing to improve upon a great product.

    Pete

  4. #4
    Join Date
    Oct 2006
    Posts
    17

    Default Re: FMBadHandler should repopulate hidden fields

    BTW, another way you could have solved the problem (without code changes) would be to load them as text fields instead of hidden fields, and then put them all in a hidden <div> section (i.e. hidden using CSS or similar).

    FMBadHandler would replace their values because they were normal fields as far as it was concerned, but the user wouldn't see them.
    Could someone explain furthur on how to do this?

  5. #5
    Join Date
    Oct 2006
    Posts
    17

    Default Re: FMBadHandler should repopulate hidden fields


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
  •