![]() |
Welcome to the Tectite Forums! You can download and get support for our free PHP FormMail (form processor) and other free software. |
|
#1
|
|||
|
|||
|
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 07:18 PM. |
|
#2
|
||||
|
||||
|
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) Root Software (http://www.tectite.com/) |
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
|
|
#5
|
|||
|
|||
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Make fmbadhandler repopulate name and email fields | Simple How-to | Jeremy | Community Support | 13 | 29-Nov-2009 12:55 AM |
| Repopulate Fields within the Error Page so user doesnt have to go back | CHood | Community Support | 0 | 18-Mar-2009 02:16 PM |
| Make fmbadhandler repopulate name and email fields | Simple How-to | Jeremy | HOWTO Guides and Tips | 2 | 15-May-2008 12:09 AM |
| Some fields not remembered using fmbadhandler | penta5 | FormMail Subscription Support | 1 | 12-Oct-2005 11:35 PM |
| My hidden fields are not hidden at all! | mikie | FormMail Subscription Support | 1 | 04-Jul-2005 09:26 PM |