We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41278
    • 3 Posts
    On our site we have forms that any anonymous user can submit, like quote requests. We use FormIt and it works great for sending emails. I toyed with the idea of creating resources to leave a db trail of the submission - the resourses later could be presented to admins & staff.

    I created a hook for formit, all is fine, I can set the template, TVs, create the doc etc. except an anonymous user cannot create a resource (so this only works if a webuser is logged in).

    1. I tried to trick the ACL into letting anonymous create resources in this resource group. Seems like anonymous cannot assigned any role. Is this true? Any way around this?
    2. Is there an easy way to temporarily log a user in, create the resource, then panic and logout?

    Thanks
      • 4172
      • 5,888 Posts
      what's the code of your hook?

      While it should be possible to create Resources for everybody, I think, that isn't a very good idea.
      Can't you create a custom-table for quote-requests?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 41278
        • 3 Posts
        Thanks Bruno, for the answer.

        Well, yes, a custom table is a possibility, this just seemed easier or maybe more modx-ish.

        My code is still very crude, something like this:

        <?php
        	$fields['createdby'] = $modx->user->id;
        	$fields['parent'] = 176; 	// Quote Request container
        	$fields['template'] = 14;	// Quote Request template
        	$fields['alias'] = strtolower($hook->getValue('mask'));  
        	$fields['hidemenu'] = 1;
        	$fields['pagetitle'] = ('Quote Request [' . $hook->getValue('mask') . ']');
        	$response = $modx->runProcessor('resource/create', $fields);
        	 
        	if ($response->isError()) {  /* An error occurred */
        		if ($response->hasFieldErrors()) {
        			$fieldErrors = $response->getAllErrors();
        			$errorMessage = implode("\n", $fieldErrors);
        		} else {
        			$errorMessage = 'An error occurred: ' . $response->getMessage();
        		}
        	   $modx->log(xPDO::LOG_LEVEL_ERROR,$errorMessage);
        	}
        	 
        
        	$object = $response->getObject();
        	$id = $object['id'];
        	$resource = $modx->getObject ('modResource', $id);
        	$resource->setTVValue ('fromEmail', $hook->getValue('email'));
        	// set all the TVs ...
                 return true;
        



          • 28042 ☆ A M B ☆
          • 24,524 Posts
          That really isn't a good idea. You don't need all the overhead of a resource to keep track of form submissions. You can easily use a custom table, and use MIGxDB to create a Custom Manager Page for it. Resources are for content, not storage.
            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
            • 4172
            • 5,888 Posts
            you can use something like formit2db or I think there was a hook in the extras, which stores formsubmissions into a custom-table.

            with MIGXdb its easy to create your package,schema... and has all what you need to create a CMP to manage the submited records.
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 41278
              • 3 Posts
              S & B,

              thanks for the pointers, of course you're right about separating content from user submitted data. I'll definitely check these out.
                • 3749
                • 24,544 Posts
                You could create a bogus user and store the information in an extended field of the user profile (or -- faster -- in the regular fields of the profile) , though a custom DB table would be much faster yet and I think MIGx would be too.

                You could also just create a file or use a big cookie.


                I agree that letting anonymous users create resources is begging for trouble. wink



                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.html
                  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
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: lbreda at Sep 16, 2012, 12:47 PM

                  1. I tried to trick the ACL into letting anonymous create resources in this resource group. Seems like anonymous cannot assigned any role. Is this true? Any way around this?
                  2. Is there an easy way to temporarily log a user in, create the resource, then panic and logout?
                  1. An "anonymous" user automatically has a role of Member, e.g. authority = 9999
                  2. not really

                  You can absolutely assign a Policy to the "anonymous" user group for the Members Role (9999).