We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42503
    • 120 Posts
    Hi,
    I need a help to complete one of my requirement. I have a product catalog, on the details of every product we have a enquiry form. Now the requirement is when ever the user click on the enquiry button the enquiry form will open with the product parent > child > sub child will get auto selected in product dropdown field. Then the user can send the form.

    Please help I have tried using
    &fiarTpl=`fiarTpl[[!getReqparam? &type=`REQUEST` &name=`product`]]`


    But no success. Please help I need that badly.

    Thank you

    Pronab
      • 46039
      • 76 Posts
      fiarTpl is for the auto responder; which is used to send the form info to additional email addresses.

      fiarTpl should contain a reference to a chunk TPL.

      This doesn't sound like what you're trying to do.


      It sounds like you're trying to send this data from the product page to the form to be filled in; You should append a query string to the URL and then write that data into the form via JS.

      This example passes the path to the page linked from, and also the ID of the page with the link; here resource 1 should be your form page:

      <a href="href="[[~1]]?key=/[[~[[*id]]]]&key2=exampleprefix-[[*id]]">Form Link</a>


      Which comes out when you land on the form page as:

      website.com/form?key1=/RESULT&key2=exampleprefix-RESULT

      Parse these values via JS.

      var queries = window.location.search;
      
      function QS(key) {
      	try {
      	    // snips the ?
      		var query = queries.substring(1);
      		// split to array
      		var vars = query.split("&");
      		// loop all items in array
      		for ( var i = 0; i < vars.length; i++ ) {
      		    // split item in array into key value pair
                  var pair = vars[i].split("=");
                  // if this item key = the key passed in - return the value
                  if ( pair[0] == key ){
      	            // if a value is blank, abort loading now
      	            // indicates an error, or a bad spoof
      	            if ( pair[1].length == 0 ){
      		            throw "ERROR: QUERY BLANK";
      	            }
                      // return value of passed key
                      return pair[1];
                  }
      		}
      		// if no match is found, throw an error
      		throw "ERROR: QUERY NOT FOUND";
      	}
      	catch(er) {
      	    // switch the error bool to true
              errorLoading = true;
              // return error string instead of expected string
              return er;
      	}
      	
      }


      Then pull values like so:

      var someKeyToFind = QS("key2");


      Which should result in the referral page's ID.

      If you're passing strings - eg the product page's title, which you can write into the form page - you'll also want to replace specials, which you can do quick and dirty like so (add the rest you need):

      QS("key2").split('%20').join(' ').split('%27').join("'");


      Now you will be able to get things like a product ID etc from a clicked link, and then select or write in the appropriate form fields.

      Writing them in with jQuery can be done via .val(); You can also select dropdown items, or just edit things like a product title. Don't forget to write things into form values if you want formit to send them on into the TPLs.

      As I said before, this is not secure in any way, but it allows you to pass options to a form with no effort. [ed. note: johnnyp last edited this post 11 years, 3 months ago.]
        • 3749
        • 24,544 Posts
        I don't know where your list is coming from or the details of how the default list item is selected, but you can sometimes use a 'selected' placeholder which is set by a fairly simple snippet on the page.
          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