We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19613
    • 70 Posts
    Hi
    I have a form that will capture information from logged in Users... Is there a way to have their ’username’ automatically captured entered into the form (hidden?) so that when the form is submitted it will automatically capture the ’senders’ names as well as the other info and send it along with to the email?
    (the form is only viewable to registered/logged-in users)

    thanks
      • 4041
      • 788 Posts
      You’ll need to make a snippet and add it in your form, for ex:

      <?php
      /*    hidden_fields snippet
      
             usage:  [!hidden_fields!]
      */
      $output ="";
      $output .="<input type='hidden' name='username' value='".$_SESSION[webShortname]."'>";
      
      return $output;
      ?>


      the above will add the line: <input type=’hidden’ name=’username’ value=’MYusername’>

      A list of a few more $_SESSION variables which you can access for loggedin users can be found here:
      http://modxcms.com/forums/index.php/topic,28064.msg170552.html#msg170552

      hope that helps smiley
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 19613
        • 70 Posts
        Thanks... I made a new snippet (does it have to be called anything particular?- i chose hidden_fields)
        I then called the snippet at the bottom of my form first ouside the </form> tag and nothing was sent in the email and then inside the </form> tage where i got accused of interferance or something by the validator.

        I know its me but I am still confused... Do I need to put anything specific in the ’report form’? Have i missed the point somewhere... sorry I am a real ’out-of-the-box’ type when it comes to PHP.

        undecided
          • 7231
          • 4,205 Posts
          Are you using this with eForm? If so you could easily use a function tied to the eformOnBeforeMailSent event to include the data. This is better than using hiddedn fields since it will be added during processing and remain private. Look in your modx install for the example at: /assets/snippets/eform/docs/eform_example_events.htm

            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 19613
            • 70 Posts
            Hi
            I am/have been using eForm. I have built a few sites with modx after moving over from Joomla and love I it, but this is the first time I have been asked to do something like this..
            i read through the document you recommended... but I have to say it was a clear as mud (probably because my brain is fried - i have been working on the site for 14 hours today (since 4.30am UK time) as i have a really tight deadline.) any easy to understand examples or ideas?

            thanks
              • 7231
              • 4,205 Posts
              Another, less technical option is to use the &sessionVars parameter:

              # &sessionVars (optional)
              Comma delimited list of $_SESSION variable names. These will be added to the list of field values before the form is displayed and can for instance be used to populate (hidden) fields. When using this parameter make sure you are not disclosing sensitive information from the session!! (a hidden field is not all that hidden afterall)
              As eForm does not parse the complete form 1st time around you will have to have the same placeholders in the form template so the form can receive the values. So for example: [!eForm &sessionVars=`jobID` ... !]and <input type="hidden" value="[+jobID+]" />

              So for example if you want the username you can simply add &sessionVars=`webShortname` to your eform call and then have the [+webShortname+] available to use in the tpl files.

              Also if you want to avoid having hidden fields validated:
              Hidden field example 2.
              Suppose you have a form where a javascript calculated value is stored in a hidden field. To avoid the hidden field being validated at all you add the following eform attribute: <input type="hidden" name="calculatedField" value="" eform="::0::" />
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 19613
                • 70 Posts
                Thanks...

                grin That makes much more sense to my very tired brain. I will give it a try after a much needed rest.
                There will be nothing sensitve in the form data/session its just a set of specifications to be forwarded to the client... it will mean nothing to anyone else... thanks for the ’heads-up’ though.

                smiley
                  • 19613
                  • 70 Posts
                  Hi
                  I created a snippet called ’namesessions’
                  <?php
                  print_r($_SESSION[webShortname]);
                  ?>
                  I also tried:

                  <?php
                  print_r($_SESSION[’webShortname’]);
                  ?>

                  I created this page & call:


                  Hello, [[namesession]] please fill in your request below,

                  [!eForm? &formid=`testForm` &sessionVars=`webShortname`&subject=`[+subject+]` &to=`[email protected],` &ccsender=`1` &tpl=`testForm` &report=`testFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &cssStyle=`ContactStyles` &gotoid=`46`  !]

                  The name does appear on the page but does not arrive with the email even though I put the call into the report as below:
                  <p>This is a response sent by <b>[+name+]</b> using the feedback form on the website. The details of the message follow below:</p>


                  <p>UserName:
                  [+webShortname+]</p>
                  <p>PrimarySport: [+PrimarySport+]</p>
                  <p>AgeRangel: [+AgeRange+]</p>
                  <p>Town: [+Town+]</p>
                  <p>County:
                  [+County+]</p>
                  <p>Postcode:
                  [+Postcode+]</p>
                  <p>Maximum:
                  [+Maximum+]</p>
                  <p>budget1:
                  [+budget1+]</p>
                  <p>budget2:
                  [+budget2+]</p>
                  <p>lottery:
                  [+lottery+]</p>
                  <p>comments:
                  [+comments+]</p>


                  I also put this in my form:
                  <input type="hidden" value="[+webShortname+]" />

                  Can you tell me what I have missed/or what I should do next... or should that work? I feel I am getting there but it just isnt working  embarrassed

                  Thanks
                  • Are you using webloginPE for the user login or the basic weblogin snippet?

                    If using webloginPE you could use a custom template to only display the username...

                    Or you could look at this snippet.

                    http://modxcms.com/extras.html?view=package/view&package=480
                      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                      AugmentBLU - MODX Partner

                      BLUcart - MODX Revolution E-Commerce & Shopping Cart
                      • 19613
                      • 70 Posts
                      I am using the basic one as far as i am aware...
                      i re-used the standard ’weblogin’ form

                      trying out your recommends....