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

    I’m trying to make a simple wedding gift registry for a mate. Essentially we’re after a list of items with a check box after each. Once the guests will log in and checks an item, either the check box will disappear and the list item will change class, or the item will disappear completely.

    Just wondering if anyone can think of a simple way of doing this using ditto, tv’s or something similar or would it be easier for me to (try to) set it up by creating the database tables manually and calling them using a form and php?

    Thanks in advance for any thoughts.

    Cheers
    Free
      • 21561
      • 16 Posts
      How about putting each gift into a seperate page and all the pages into a container. Then use ditto to build the list for that container.

      When a user selects a gift you can run a snippet to update database so that page’s publish is set to 0 and that way that gift is no longer displayed in the ditto list.

        • 4455
        • 76 Posts
        cackalufabogus Reply #3, 15 years ago
        That sounds easier than anything I could come up with laugh

        I’m a front end guy, not a developer any ideas on how to get a snippet like that to work?
          • 21561
          • 16 Posts
          So I thought you could use eform and ditto to solve your problem. That would give you the most control over the look without having to touch the back end.

          So I created a document container called gifts with rich text off ( you can call it whatever you like)

          Then put these two snippet calls on that page

          [!GiftStuff!]
          [!eForm? &formid=`gf` &eFormOnBeforeFormParse=`getGifts` &eFormOnBeforeMailSent=`removeGifts` &tpl=`giftForm` &thankyou=`thanks`!]


          The GiftStuff snippet holds the getGifts function used by eFormOnBeforeParse and the removeGifts function used by eFormOnBeforeMailSent.
          The eform call is going to run the getGifts function before the form is diplayed and that function will run a ditto call to pull the gift pages inside the gifts container. The eFormOnBeforeMailSent runs the removeGifts function which will un publish any documents that the user selects using the checkboxes.


          Here is the GiftStuff snippet

          // dynamically insert ditto output into eforms
          function getGifts(&$fields, &$templates) {
              global $modx;
          
              // run ditto from php
              // if you ditto call is more complicated just add more $params variable ($params['Ditto Param without the &'])
              $params['tpl'] = 'giftRow'; // assign giftRow template to Ditto
              $giftList = $modx->runSnippet('Ditto', $params); // run ditto
          
              // create gifts placeholder for eform
              $templates['tpl']=str_replace('[+gifts+]', $giftList, $templates['tpl']);
          }
          
          // process form submit
          function removeGifts(&$fields) {
              global $modx;
              $table = $modx->getFullTableName('site_content');
          
              foreach($fields as $field=>$value) {
                  //split the checkbox name on the dash
                  list($prefix, $title) = split("-",$field);
                  // if prefix everything left of the dash is gift and the value is not blank then run database update
                  if($prefix == 'gift' && $value != '') {
                  $id = $modx->db->escape($value);
                  if(!$unpub = $modx->db->query("UPDATE $table SET published = 0 WHERE id = $id")) echo '<div class="error">Were Sorry! There was a problem and your selection was not saved</div>'; return false;
              }
          }
          return true;
          }


          You will also need to create a chunk for your ditto call. I called it giftRow. You will notice that in the getGifts function above there is a line with $params[’tpl’] = ’giftRow’. You will need to change that line to whatever your chunk is called or leave it as is if your chunk is called giftRow. Also remember that you need to create a new $params variable for every ditto parameter you want to run ( eg. $param[’sortBy’] = ’editedon’; ). Also note you are not using backticks here you are using single quotes.

          My ditto template is pretty basic you can change yours however you want just make sure the name for check box is gift-[+id+]. It will not work without it.
          I used the pagetitle to put the title of the gift. You could use whatever document fields you like. Basically ditto the way you normally would.

          giftRow chunk
          <input type="checkbox" name="gift-[+id+]" value="[+id+]" eform="[+pagetitle+]::0">[+pagetitle+]

          and lastly the eform tpl

          giftForm

          [+validationmessage+]
          <form action="[~[*id*]~]" method="post" name="giftForm" id="gf">
          [+gifts+]
          <input type="submit" name="submit" value="Purchase Gift">
          </form>


          The [+gifts+] placeholder is created by the getGifts function from above

          I almost forgot. In the eform snippet call there is a thanks chunk you need to make or you can take it out and use the default thank for eform.

          Hope that helps let me know if you are having any problems or questions. I was in a bit of hurry so let me know if there are any mistakes.

          Angelo
            • 4455
            • 76 Posts
            cackalufabogus Reply #5, 15 years ago
            WOW, thanks dude, that looks awesome!

            I’ll give it a try when I get a sec next week.

            Thanks heaps
            Free