We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3632
    • 22 Posts
    I have posted about this in another thread but I think it deserves one of its own.

    Say I have a select element that I want to output in my form - the basic HTML output to the browser would be:

    <select id="gender" name="gender">
    <option value="male">Male</option>
    <option value="female">Female</option>
    <option value="Undisclosed">Undisclosed</option>
    </select>
    


    Now suppose I want to have the ’Undisclosed’ option selected by default rather than the ’Male’ option which would be displayed using the code above. I would want to have the following HTML output to the browser:

    <select id="gender" name="gender">
    <option value="male">Male</option>
    <option value="female">Female</option>
    <option value="Undisclosed" selected>Undisclosed</option>
    </select>
    


    Now the important thing here is the ’selected’ attribute in the ’undisclosed’ option. In my experiments with eform the form parser seems to strip out that attribute no matter what way I enter it. I’ve tried:

    selected
    selected="selected"
    selected='selected' (which is the way eform itself seems to reprint the selected option in the select element when validation is unsuccessful).
    selected="true"
    selected="yes"
    


    The attribute is removed from both eforms based on a chunk template and ones based on snippets.

    Any suggestions?
      • 30223
      • 1,010 Posts
      I’ve come across this in another post somewhere and suggested a solution but I can’t remember when. I’ve uploaded a new version with some changes that should help you. Download from the repository.

      This should allow you to do the following and retain the default selected value:

      <select id="gender" name="gender">
      <option value="male">Male</option>
      <option value="female">Female</option>
      <option value="Undisclosed" selected="selected">Undisclosed</option>
      </select>
        • 23491 ☆ A M B ☆
        • 1,056 Posts
        Quote from: TobyL at Jan 14, 2009, 05:08 PM

        [...] I’ve uploaded a new version with some changes that should help you. Download from the repository.

        You just made my day! Too bad this didn’t make it into the final 0.9.6.3 build sad In fact I modified a custom copy of the MODx installer JUST YESTERDAY for eForm: PHx workaround and radio/select default value issue. Gotta love it.

        NOTE: Just using selected will get stripped, but using XHTML selected="selected" works great! Consider this a feature to help you pass strict validation! wink

        Jason/Ryan, I know the SVN branch for 0.9.6.3 is officially closed in preparation for v1.0, would you guys be open to a manual rebuild w/ eForm 1.4.4.6 with my assistance? Tested on 3 installs successfully today...Let me know, and I can get you a fresh .zip and .tar.gz!
          Mike Reid - www.pixelchutes.com
          MODx Ambassador / Contributor
          [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
          ________________________________
          Where every pixel matters.
          • 3632
          • 22 Posts
          Thanks for the quick response - and great that you are encouraging XHTML standards - definitely the way to go. Having used the eform system over the past few days I think my favourite feature is the extensible validation - would be nice to see some ajax version a la asp.net down the line.
            • 349
            • 76 Posts
            Hi TobyL

            i downloaded the latest version but selected="selected" still gets stripped :-(
            Added the following code:
            <select id="cf[+anliegen+]" name="anliegen">
            <option value="Kontakt">[+kontaktLabel+]</option>
            <option value="Produktprobe" selected="selected" conform="yes">Produktprobe</option>

            conform="yes" doesn´t get stripped.

            I also noticed, that in your files the version number still says 1.4.4.5.

            Addition:
            In &eFormOnBeforeMailSent i have no access to the $params of eForm. This is bad if you are writing your own E-Mail Handler or something other and want to use the variables.
            So could you please add the following code to line 377 (approx.):

            elseif ($eFormOnBeforeMailSent($fields,$params)===false) {