We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9439
    • 90 Posts
    Hi, been away from MODX for a while and I have a requirement to look up addresses from the UK postcode database. I had a search through the forums and couldn't one instance of anyone else requiring this. Has anyone got any pointers for looking up a database from a form? Presumably I can just use Formit and maybe Formitretriever? The actual api looks pretty simple. Ideal Postcodes provide a link like this example: https://api.ideal-postcodes.co.uk/v1/postcodes/ID11QD?api_key=iddqd (ID11QD is a sample postcode)

    Thanks

    David Heriot
      David Heriot
      pfsmedia
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Yes, I would use FormIt, mostly to simplify validating the user's submission. You would use a custom FormIt hook to make the API request and process the return.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 9439
        • 90 Posts
        Thank you Susan
          David Heriot
          pfsmedia
          • 9439
          • 90 Posts
          This also looks up and validates a bank sort code and account number. It works as a standalone php form but it's not clear to me how to then use formit and a snippet to achieve the same result.

          The form, stripped down is:

            <label for="sortcode">Sort Code<span class="error">[[!+fi.error.sortcode]]</span></label>
            <input type="text" name="sortcode" value='<?php if(isset($_POST['sortcode'])) { echo htmlentities ($_POST['sortcode']); }?>' /> // set to retain the input in the input field
          
          <label for="AccountNumber">Account Number</label>   
             <input type="text" name="AccountNumber" value='<?php if(isset($_POST['AccountNumber'])) { echo htmlentities ($_POST['AccountNumber']); }?>' />   // set to retain the input in the input field
             <input class="button" name="click" type="submit" value="Check bank account details" />   
          


          PHP

          if(isset($_POST['click']))
          {
             $sortcode = $_POST['sortcode'];
             $AccountNumber = $_POST['AccountNumber'];
          .
          > external database call, which returns array
          .
          $data = $pa->HasData();
             foreach ($data as $item)
                {
                  $varVerifyAccount = $item["AccountVerification"];
          more items from array...
          
          


          So the external call checks the account and we use $varVerifyAccount to advise the user whether or not the account may be used. You can see how the form looks here: http://pfsmedia.net/letusfixit/account-form.php

          Can someone give me a steer how to code the snippet? Also, you see I'm keen to retain the values in the input fields after submit is clicked. Not sure how to do that in formit.

          Thanks

            David Heriot
            pfsmedia
            • 9439
            • 90 Posts
              David Heriot
              pfsmedia