We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36931
    • 206 Posts
    Hello
    I am sorry if my question is stupid but I can not get the value of input of a form

    I created a CHUNK and I past a simple form with two input. I add teh CHUNK to my template named 'stage'.
    <form class="form-inline" method="get" action="[[~[[*id]]]]">
      <div class="form-group">
    
        <label for="input_place">Rechercher un stage</label>
        <input type="text" class="form-control" id="input_place" name="input_place" placeholder="Lieux">
      </div>
      <div class="form-group">
        <label for="input_date">ou</label>
        <input type="date" class="form-control datepicker" id="input_date" name="input_date" placeholder="sélectionnez une date">
    
      </div>
      <button type="submit" class="btn btn-default">Envoyer</button>
    </form>
    <hr>
    

    I created a resource and I chosed the template 'stage'

    Finaly, I created a SNIPPETS and I pasted PHP code. At the begining of my snipppet I psted the following code
    foreach($_GET as $k => $r)
    {
    	echo $k.'=>'.$r.'<br>';
    }
    
    


    When I send my form with some values ("toto" and "titi", the foreach of my snippet do not show me 'toto' and tit' but
    cultureKey=>
    q=>stages/stage.html
    while it should display
    inout_place=>toto
    input_date=>titi

    The is not a MODx class or something else, which let me get the form value?
    How can I get the input value from a snippets?

    Thank a lot [ed. note: pierrot1010 last edited this post 9 years, 11 months ago.]
      • 36931
      • 206 Posts
      It seams to be a cache problem.
      Bur now I try to send the form with the post method

      I also foud the following
      
      foreach($_POST as $ki => $ri)
      {
      	echo $ki.' p>'.$ri.'<br>';
      }
      
      echo $modx->resource->get('input_place'); echo '<br>';
      echo $modx->resource->get('input_date');


      Again nothing is showed. I clear the cache and nothing is displayed shocked(

        • 36931
        • 206 Posts
        I solved my problem.

        I called my snippets as the following
        [[filterStage? &parents=`14` &date=`2016-11-22` &place=`genev`]]

        I added a !
        [[!filterStage? &parents=`14` &date=`2016-11-22` &place=`genev`]]


        And now each time I send my form, I can display the value with this:
        foreach($_POST as $ki => $ri)
        {
        	echo $ki.' p>'.$ri.'<br>';
        }


        Now, this was really stupid
        //echo $modx->resource->get('input_place'); echo '<br>';

        because it look for an element of my resource (which does not exist) and not of my from.

        However, this should work
        echo $modx->resource->get('id')


        But there is something like this, to get the value of an input of my form? (to avoid a foreach loop)
          • 3749
          • 24,544 Posts
          Is this what you're looking for?

          $val = $_POST['fieldname'];
            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