We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24624
    • 8 Posts
    I know this is a stupendously basic-sounding question....IF it were in just HTML, but MODx has me stumped. I have a snippet that pulls a list of years from a database table, formatting into a dropdown listbox. The select element has an onclick attribute of "javascript:submit" on it. But when it submits, instead of it going to the "current" page with the year parameter, it goes to index.php with no id, only the year. That is:
    I’m on index.php?id=10.
    I want to pick a year from the dropdown so that after submit (to the same page it’s already on) the information displayed uses the year parameter. So I would expect to arrive at this:
    index.php?id=10&year=2008
    But instead, I arrive at:
    index.php?year=2008
    Which is the wrong page entirely, that is my Home page.

    So my questions continue....
    How do I tell it to submit to itself, not to the naked index.php?
    If I were to figure out how to get it to go to index.php?id=10&year=2008, how would I read the value of the year parameter? I have [[*year]] defaulting to a @SELECT max(year) FROM table, and so that’s what I get. I want to access the $_GET variable, either and/or both in the resource id=10, and inside snippets called from there. I’m not catching on, and the documentation....well, has anybody actually tried to learn how MODx works from the documentation? It’s enough to make a large tough php programmer cry.
    Then, how do I tell my select dropdown to make the previously-selected value (now passed in on the url) to be what’s selected in the dropdown? I’m using a TV of the output type "HTML Tag", tag name option. But I don’t see any way there to have it pre-select a particular option.
    This is my third go at trying MODx over the past 18 months or so, the previous two times I gave up in total abject frustration. I thought I was getting the hang of it once I finally got a few things figured out, but now getting caught on stuff like this that is otherwise so childishly simple is really killing me.
    Is there a source of documentation better than that hosted on this site? Half of that documentation is dead links. The other half is haphazard at best, contradictory to itself at worst, and doesn’t explain anything in between there. I know, free software.....but I’m very very very frustrated with this. Without a way to get off of noob status, there’s no way to get off of noob status.....

    This is on Revo 2.0, fresh install earlier today, PHP Version 5.2.13, mysql 5.1.47, Apache/2.2.15 (CentOS)
      • 12028
      • 152 Posts
      Do you have a:
      <base href="[[++site_url]]" />
      in the HTML header in your template?
      And maybe you can declare a target to your javascript.submit with something like this:
      [[++site_url]][[~[[*id]]]]

      Hope this helps!
        - A small step for mankind, so why not take two...

        Working with web production, graphic design/workflow, photo and education - but are trying to get a life in between!
        • 24624
        • 8 Posts
        Thanks for the suggestion, but, still the same result. Here’s my form code.


        <form action=[[++site_url]][[~[[*id]]]]>
        <table border=0 bordercolor=darkorange>
        <td class=select><b>Select Season:</b></td> <td class=select>
        <select name=year onchange=’javascript:submit();’>
        [[*allyears]]
        </select>
        </td>
        </table>
        </form>


        The [[*allyears]] returns:
        <option id="yrs">2010</option><option id="yrs">2009</option><option id="yrs">2008</option><option id="yrs">2007</option>...etc etc for many years.
        I suppose I could put a hidden text input field in here to pass the id parameter, but I just figured there was a more elegant solution...i.e., something already built in. But then I still don’t have a way to make the year passed in be selected in the dropdown unless I just code up a special snippet just for this. It seems like there ought to be something for this already in MODx since it has this fancy option-tag trick. Needs a "selected" property. Unless again, of course, it does have it and I just don’t know it.
          • 3749
          • 24,544 Posts
          Try this:

          <form action="[[~[[*id]]]]? &myVar=`[[*allyears]]`"> 


          Then you can retrieve myVar with

          $_GET['myVar']


            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