We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    Running: Modx Evolution 1.0.5

    I've been working to get eForm to send the entered form data to two email address, while also saving it to a database table in the current modx database. I have it sending to the two email addresses fine, but I'm having trouble getting it to save to the database in addition to that. I'm a novice at database stuff, so I'm hoping I'm just missing something easy.

    I've pretty much based it all off of this guide in the wiki: http://wiki.modxcms.com/index.php/Use_eForm_to_Store_data_into_Database

    Here is the eForm snippet call plus the call to the save to database snippet:
    [!contactDatabaseSave!]
    
    [!eForm? &formid=`feedbackForm` &to=`[email protected],[email protected]` &tpl=`eFeedBackForm` &report=`eFeedbackReport` &thankyou=`eFeedBackThanks` &mailselector=`department` &vericode=`0` &subject=`Web site feedback` &eFormOnBeforeMailSent=`contactDatabaseSave`!]


    Here is the save to database snippet:
    <?php
    function agregarCargas( &$fields )
    	{
    		global $modx;
    		// Init our array
    		$dbTable = array();
    		$dbTable['name'] = $modx->db->escape($fields['name']);
    		$dbTable['email'] = $modx->db->escape($fields['email']);
    		$dbTable['fax'] = $modx->db->escape($fields['fax']);
    		$dbTable['phone'] = $modx->db->escape($fields['phone']);
    		$dbTable['address'] = $modx->db->escape($fields['address']);
    		$dbTable['address2'] = $modx->db->escape($fields['address2']);
    		$dbTable['city'] = $modx->db->escape($fields['city']);
    		$dbTable['state'] = $modx->db->escape($fields['state']);
    		$dbTable['zip'] = $modx->db->escape($fields['zip']);
    		$dbTable['Country'] = $modx->db->escape($fields['Country']);
    		$dbTable['Patient'] = $modx->db->escape($fields['Patient']);
    		$dbTable['heard'] = $modx->db->escape($fields['heard']);
    		$dbTable['procedure'] = $modx->db->escape($fields['procedure']);
    		$dbTable['comments'] = $modx->db->escape($fields['comments']);
    		// Run the db insert query
    		$dbQuery = $modx->db->insert($dbTable, 'form_data' );
    		return true;
    	}
    ?>


    When I attempt to send the form with these things in place, I just get a server error:

    HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.


    I appreciate any help! [ed. note: firebot6 last edited this post 12 years, 2 months ago.]
    • The name of the function is what eForm needs, not the name of the snippet. You can even have several functions in the same snippet if you have different eForm events being handled. The value of the parameter in the eForm snippet call should be `agregarCargas`

        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
        • 36760
        • 136 Posts
        That got me somewhere. I guess I didn't realize it because they had the same name in the tutorial.

        Now I'm just getting this Modx Parse Error error:
        Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'procedure,comments) VALUES('Preston D','[email protected]','555-55' at line 1


        Is the "at line 1" referring to any particular file? It at least seems like it's picking up all the form data, it's just having issues storing it. **EDIT** I guess it's probably talking about the code in the snippet, but I'm not seeing anything wrong, at least with my limited experience working with this.

        I realized that step one in the tutorial may not have been completed (I wasn't the one who made the table). Would that be what's causing it? The table is there, but I'm not sure if it was given any areas to store the specific data (i.e. `fullname` varchar(255) NOT NULL,). [ed. note: firebot6 last edited this post 12 years, 3 months ago.]
        • That's a MySQL error, it doesn't like the query that is being created.

          You definitely need to have the table set up to store the data you want.
            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
            • 36760
            • 136 Posts
            If the table is setup correctly, is there anything else that would cause it to not like the query? The table was setup with the query/command this time, but I'm still getting the error when I submit the form.

            I wasn't given access to create the table, so I'm taking the person's word on it. If there's no other reason, I'll see if I can get in to take a look at the table.