We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Willi Waizenegger Reply #1, 14 years ago
    I've been using FormSave (http://modx.com/extras/package/formsave) for several sites now and really love it. As you know, it serves to save form (FormIt form) data in the db for later retrieval.

    Now, I've recently discovered Formz (http://modx.com/extras/package/formz), which I'm liking a lot. So far, I've only experimented with it outside of a paying-client setting, but I like it. As you may know, Formz allows a code-challenged end user to quickly create and publish forms on their site at will. Really cool.

    Kudos to both sets of authors, by the way.

    However, I think it would be just ducky to be able to meld the two systems, so that the site owner could get saved data from forms they created. I'm wondering how to go about accomplishing that.

    Things I've noticed:

    1. In a FormIt only form setup, the form code (which utilizes the FormSave hook) looks something like this:

    [[!FormIt?  
    &hooks=`spam,FormSave,email,emailUser,redirect`
    &emailSubject=`Submission from The XXXX Contact Form`
    &emailTpl=`EmailChunk`
    &emailTo=`[email protected]`
    &redirectTo=`1`
    &fsFormTopic=`Contact`
    &fsFormFields=`firstName,lastName,email,telephone,street,cityTown,state,zipcode,country,text` 
    &validate=`firstName:required,
    lastName:required,
    telephone:required,
    email:required,`
    ]]
    
    [[!+fi.error.error_message:notempty=`
    <p>[[!+fi.error.error_message]]</p>
    `]][[!+fi.error.rampart]
    
    ...the rest of the form code...
    
    ]


    2. In a chunk that comes along with Formz called formtpl.chunk.tpl (core > components > formz > elements > chunks > formtpl.chunk.tpl) there is code that looks like this:

    [[!FormIt?
    	&hooks=`[[+action]]`
    	&excludeFields=`submit[[+id]]`
            &submitVar=`submit[[+id]]`
    	&formid=`[[+id]]` [[- "Form ID"]]
    	&store=`1`
    	&storeTime=`900`
    	&successMessage=`<p>[[+success_message]]</p>`
    	&emailTo=`[[+email:default=``]]`
    	[[+validation:notempty=`&validate=`[[+validation]]``]]
    	[[+validationText:notempty=`[[+validationText]]`]]
    ]]
    
    [[!+fi.successMessage]]
    [[!+fi.validation_error_message]]
    
    <form class="form [[+identifier]]" action="" method="post">
    	<fieldset>
    		[[+fields]]
    	</fieldset>
    
    	<div class="actions">
    		<input type="submit" name="submit[[+id]]" value="[[+action_button:default=`Submit`]]" class="btn primary" />
    	</div>
    </form>
    


    ...which looks similar to the first bit of code.

    So, what I tried was melding the two by changing the Formz tpl code to look like this:

    [[!FormIt?
    	&hooks=`FormSave,[[+action]]`
    	&excludeFields=`submit[[+id]]`
            &submitVar=`submit[[+id]]`
    	&formid=`[[+id]]` [[- "Form ID"]]
    	&store=`1`
    	&storeTime=`900`
    &fsFormTopic=`Misc`
    &fsFormFields=`[[+fields]]`
    	&successMessage=`<p>[[+success_message]]</p>`
    	&emailTo=`[[+email:default=``]]`
    	[[+validation:notempty=`&validate=`[[+validation]]``]]
    	[[+validationText:notempty=`[[+validationText]]`]]
    ]]
    
    [[!+fi.successMessage]]
    [[!+fi.validation_error_message]]
    
    <form class="form [[+identifier]]" action="" method="post">
    	<fieldset>
    		[[+fields]]
    	</fieldset>
    
    	<div class="actions">
    		<input type="submit" name="submit[[+id]]" value="[[+action_button:default=`Submit`]]" class="btn primary" />
    	</div>
    </form>
    


    The changes involve adding the FormSave hook to the top of the code, as well as this bit:

    &fsFormTopic=`Misc`
    &fsFormFields=`[[+fields]]`


    ...but that doesn't work. The form still works okay as it did without the FormSave part, but there's still no data being saved in the db.

    I'm suspecting something to do with the

    &fsFormFields=``


    ...part because the original (non-Formz form) declares all the fields to be saved as a list (Array? Would that be the proper term?), with commas as delimiters. But, I'm not sure.

    Can any of you chime in here? I appreciate it in advance.

    Install running on MODx Revolution 2.2.2. [ed. note: waizen last edited this post 14 years ago.]
      • 37246
      • 128 Posts
      I could be wrong, but i believe it has to do with the order in which your hooks are being processed. Formz' [ [+action]] hook includes, email, savetodb and redirect. I believe what you want to do is insert your formsave hook between email and redirect, which you can't really do at the present(though i'm trying to get Andrew to break the hooks up to support something like this as well as FIAR).

      In the meantime, you'll want to insert your code in the fmzForm_database_email snippet directly.

      Right before the
      return true;

      you'll want to add the snippet equivelent of the formsave. For FIAR it was
      $modx->runSnippet('FormItAutoResponder', array('hook' => $hook));
        I LOVE MODX! | greyskymedia.com
        • 37042
        • 384 Posts
        Hi Willi. I understand your question but wondered what advantage FormSave had over the native ability in Formz to save results to a database?
          ...
          • 31902
          • 342 Posts
          Quote from: eladnova at Nov 24, 2012, 01:07 PM
          Hi Willi. I understand your question but wondered what advantage FormSave had over the native ability in Formz to save results to a database?

          @eladnova : When I first asked this question about a month ago, I had just started playing with Formz. At the time, I didn't notice that it could export entries as CSV files. For my clients, that seems to be good enough for now and I've since put this question to bed. However, FormSave seems to offer multiple export options such as CSV (comma separated), CSV (semicolon separated), printable HTML and XML. If you need those, then it would be good to meld the two solutions somehow. Unless, Formz can do all those things as well and I've missed it.

          As of yet, I haven't utilized Formz in any actual client project, so I don't know it that well.
            • 37042
            • 384 Posts
            I tried Formz yesterday for the first time. It's a nice add on and I can see the benefits for clients. At the moment though, I am using hand coded forms with Formit and using FormSave to store the results. I think I've more control over the whole mechanism that way but thanks for bringing Formz to my attention. Might road test it for a client soon.
              ...