We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9990
    • 7 Posts
    Hi all,

    to create TV with a dropdown list of a documents child pages, I use the follwing code:

    @EVAL $s=$_GET['id']; return mysql_query("SELECT pagetitle FROM modx_site_content WHERE parent = $s");


    Now I would like to add a ’null’ option, so one can either select one of the childpages or nothing, does anybody have an idea how to get this done?

    thanks!

    ::fouk::
      • 3749
      • 24,544 Posts
      I haven’t tried it but it might work to just add this in front of the @EVAL:

      No Selection||


      [Update] Sorry, doesn’t work. It looks like @EVAL has to be the first thing on the line.


      You can give the TV a default value that will be set if nothing is chosen:

      @INHERIT NoSelection 


      That won’t give you a NULL value, but you should be able to identify no selection in your code (and translate it to NULL if you want). I can’t think of any easy way to put "No Selection" at the top of the list, but maybe someone else can.


        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 9990
        • 7 Posts
        Bob, thanks for your reply.

        yes, it looks like Mr. @EVIL does not ecxept any double pipe constructions, neither before nor after himself, I had tried that too.

        also I had no luck with your second suggestion, a default that’s not defined in the option values does not show up in my lists.

        hm .... looks like this has to be done in a php snippet.


          • 29774
          • 386 Posts
          Indeed - @EVAL $modx->runSnippet(’’mySnippet").

          But *please* don’t do this where $s is subsequently used in an SQL statement:

          $s=$_GET[’id’]

          At the minimum ensure the global is an integer:
          $s = intval($_GET[’id’]);
            Snippets: GoogleMap | FileDetails | Related Plugin: SSL