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

    Back again with another question;)

    I'm having some issues getting fields to populate with values based off of the url query string. It seems to be working fine offline as a static HTML but I'm having some problems getting it to work on my modx setup.

    Basically I have a homepage with some fields and a button which once submitted takes you to the register page with the url of '/register/&?register-form&serial=123123123' however the serial input remains blank.

    Any ideas on where I could be going wrong?

    Thanks,

    This question has been answered by claytonk. See the first response.

      ■ email: [email protected] | ■ website: https://alienbuild.uk

      The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
      • 5430
      • 247 Posts
      Are you using the login.register snippet on your registration page? If so, you need a prehook to populate the form fields via GET. (https://rtfm.modx.com/extras/revo/login/login.tutorials/login.using-pre-and-post-hooks).
        • 17301
        • 932 Posts
        Thanks for your reply.

        I am using the login.register snippet and I've read the documentation on using pre-post hooks but would you mind explaining a little futher on how you get the data from the url into the fields? I understand getting the data from the database just not sure how you go about from the url.

        Thanks,
          ■ email: [email protected] | ■ website: https://alienbuild.uk

          The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • discuss.answer
          • 5430
          • 247 Posts
          Data passed by query string in your URL is what's called a GET request, and is available in PHP via the GET array. In other words, if you have the parameter '&serial=123123123' in your URL, you can access that data in any snippet via $_GET['serial']. You don't have to do this with a hook, you could simply run a simple snippet before your register snippet or inside the form itself that passes your GET array into placeholders. Super quick example. Let's say you have a form

          <form>
              <input type="text" name="serial" value="[[+serial]]" />
          </form>
          


          You could create an equally simple snippet, let's call it getSerial, before the form and use it to generate the [[+serial]] placeholder. You could also call the snipped directly in the value attribute itself instead of using a placeholder, but if you're wanting to grab more than one value, you'll need to use placeholders instead so you don't have to call a different snippet for each value. Here's what getSerial might look like:

          if (isset($_GET['serial'])){
             $modx->setPlaceholder('serial',$_GET['serial']);
          }
          


          If you call [[!getSerial]] before your form output, the serial placeholder should contain the value of the &serial parameter in your URL string. Did I understand your question?