Results 1 to 5 of 5

Thread: multi_keep and dynamically created select options

  1. #1
    Join Date
    Feb 2006
    Posts
    20

    Default multi_keep and dynamically created select options

    Formmail's multi_keep handles select boxes, but will only set the selected value if the corresponding option is hard-coded in the html. So, in select boxes with dynamically created options, formmail's multi_keep does not set the selected value back to what it was.

    Since I do want to use dynamically created options and use formmail to make the form remember the field value when the user goes forward and back through the pages of a form, I am now working towards a solution uses the formmail multi-keep to pass on a hidden field value back and forth accross pages.

    What I am doing is as follows. I have some select boxes (eg Nationality) with some hard-coded options (eg British, American), the last one of which is 'Other'. When 'Other' is selected, the user is prompted to manually fill in a new option (eg Canadian), which is dynamically created and selected in the select box.
    At the same time, an onChange function is used to put the value of that selectbox (ie Canadian) into a hidden field (eg OtherNationality), which until then had a null or empty value (ie 0 or ""), and the multi_keep array of formmail is set to include that hidden field.
    Then, after going forward to the next page and back to the first page, the idea is to set the select box (ie Nationality) back to the original value (ie Canadian) by setting its value to that of the hidden field (ie OtherNationality). There is more to that than simply equating the value of one field to that of the other, but before it gets that far, something goes wrong.

    In the process of scripting this, multi_keep passed the hidden field value forward to the second form page, but not back again to the first form page. I am absolutely puzzeld by this.
    Using alerts to test the flow, it is clear that everything works on page one, then the hidden value is still remembered on page two, but after going back to page one the hidden value is reported as undefined.

    So, the question is: can formmail's multi_keep remember the value of a hidden field forward and backwards, or did I do something wrong?
    My best guess at the moment is that multi_keep is able to remember a hidden field value through any page where the hidden field is not present, is unable to set the value of a hidden field, and then loses the value remembered by multi_keep in the page where the hidden field is present.

    I made a temporary test form at www dot elslawyer dot org/forms/formp1.php (sorry for not showing the url in the usual way), where you can test what I mean.

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

    Default Re: multi_keep and dynamically created select options

    Hi,

    Thanks for providing the example. It's clear what's happening now.

    You were on the right track - FormMail doesn't try to restore "hidden" fields to a previous value. This makes a lot of sense in 99.99% of cases.

    So, to get your mechanism working, "OtherNationality" needs to be a "text" field not a "hidden" field.

    The problem then becomes how to hide this on the form. Use CSS to achieve this:
    HTML Code:
    <input type="text" name="OtherNationality" style="visibility:hidden;" value="0" />
    FormMail can then put the correct value back in, but you don't get to see the field.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Feb 2006
    Posts
    20

    Default Re: multi_keep and dynamically created select options

    That was it, it now works! - That is, the value is passed on, I still have to script setting the value. Later I will post the scripting in case it is of use to others.

    BTW, I made a slight modification to the 'hidden text' fields; I used
    style="display='none';"
    . In this way, the field receives events and does not take space in the document flow.

    Thanks!

  4. #4
    Join Date
    Feb 2006
    Posts
    20

    Default Re: multi_keep and dynamically created select options

    One more question on this.

    In order to reload the value into the field using javascript, I need to refer to the field name. For example, referring to a field named myfield in a form named myform it would be document.myform.myfield.
    However, for multiple select fields, formmail requires the square brackts in the name. So the field name would for example be myfield[]. When I refer to that as document.myform.myfield[], I get javascript errors.

    Any ideas?

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

    Default Re: multi_keep and dynamically created select options

    Hi,

    I think that's a JavaScript question....

    FormMail only needs the "[]" in the name attribute of the field definition - that's the way PHP operates. You don't use "[]" anywhere else.

    For multi select fields, you have "options". So, in JS you need to run through the field.options array, and set the field.selectedIndex member to the correct option.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Easier access to configuration options
    By FLEB in forum Your Suggestions
    Replies: 4
    Last Post: 24-Apr-2007, 09:13 AM
  2. select options in html email
    By sinbad in forum Community Support
    Replies: 4
    Last Post: 25-Jun-2006, 03:33 AM
  3. formmail remembrance of dynamically created select boxes
    By ewel in forum HOWTO Guides and Tips
    Replies: 0
    Last Post: 23-Feb-2006, 03:18 PM
  4. Replies: 0
    Last Post: 16-Feb-2006, 10:56 AM
  5. Using required for select dropdowns?
    By stevie in forum Community Support
    Replies: 1
    Last Post: 08-Feb-2006, 04:31 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
  •