I’m trying to use FormLoom 4 and FormSnap for forms. However, they seem to basically be setup to submit and e-mail the data. I want to instead create a form and then specify to post to a specific PHP page so that I can pull the POST data and save it to a database (and do other stuff with it).
The only options I see are Success and Error URLs, but they only go there after it runs their own processing for email. Is there a way I can do this?
Also I’ve had to add PHP and JS in the code areas to populate the select lists from the database. It works, but seems like I’m having to do a lot of “hacks” to get all these things to work. Is there a better way/stack/tool for RapidWeaver to handle populating lists and posting the data? Of course I could just add an HTML stack and write the whole page if it comes to that.
Yes, you could … ahem ‘work’ with FormLoom or one of the other form solutions to intercept the post data but as you have found that can be overkill depending on what you are trying to do.
I’m still on FormLoom 3 but I presume you have looked at using things like the ‘Custom POST’ url and the PHP overrides?
Whenever I have needed to do something different to the happy paths offered by FormLoom/FormSnap (which are brilliant products) I’ve used this:
It’s a breeze to build exactly what you need, they look tremendous, are highly customisable, and significantly you get full control of the post data via your PHP, or whatever you want to use, on the back end. I’ve used these to hit back ends powered by Java/Go and Python as well as PHP - no issues at all because after all you are just harnessing plain old http methods/Ajax.
Wonderful reply. Thank you! Yes I used the custom PHP/JS areas. That’s how I had to populate the select lists. I never did notice that custom URL though, but just tried it and it seems to be iffy. The submit button just spins and happens (perhaps the overkill on processing for that stack).
Either way I took a look at Sky Forms and it looks like that is a reasonable solution. I don’t mind adding HTML as long as it’s consistant and good looking. I’m a programmer, not a designer… That’s where the RapidWeaver comes in to help.
What happens is that FormLoom POSTs your data to the custom PHP and waits on that page for a Success result. In the array, if you want FormLoom to stay on the original page and just display a message, change the redirect code to 0. Otherwise, change it to 1 and add the redirect URL.’
One thing to watch is the “Result” - must use ‘good’ - all lowercase. If you use ‘Good’ - it will fail.
If the Custom PHP fails, you still need to send a “Result=fail” back to FOrmLoom
Thanks for all of your help guys. I’ve been experimenting a lot with various stacks and HTML solutions and thing I have found solutions for each issue thanks to your help. I tried for the best organized solution. I came up with another issue to solve, but it’s not a big one. This was all tested with FormLoom 4 Demo.
Issue 1: Load Select List from database Solution 1:
Step 1: Create a PHP file that connects to your database, runs a query, fetches results, and returns them via json_encode (going to be used be ajax call in next file)
Step 2: Create a JS file (Ex: test-code.js) that will be the javascript for your page. It simply has the functions in it that will populate your select lists. This function will run the ajax call to the PHP file above and then directly add the options to the select list. The name to use for the select is mentioned on the list control in it’s properties. See below;
function PopulateOrganizationTypes()
{
$.ajax(
{
url: ‘/code/db/getOrganizationTypes.php’,
type: ‘post’,
dataType: ‘json’,
success:function(response)
{
var len = response.length;
$("#fl-item-3").empty();
$("#fl-item-3").append("<option value='0'>All</option>");
for( var i = 0; i<len; i++)
{
var key = response[i]['organizationTypeKey'];
var name = response[i]['organizationType'];
$("#fl-item-3").append("<option value='"+key+"'>"+name+"</option>");
}
},
});
}
Step 3: Add the JS include in the HTML Code - Head section for your page (not the FormLoom control)
Step 4: In your FormLoom control JS (“WARNING! Use at your own risk” area) call the function
PopulateOrganizationTypes();
Step 5: Enjoy!
Issue 2: Posting to a new PHP for processing/routing Solution 2:
Step 1: Create the PHP file for processing and add Skyomac’s code at the end for success, processing and routing
Step 2: Add that new page to the Custom URL
Issue 3: New Issue - Calling JS function instead of a Custom URL
This would be nice so that I could just call a JS function to save and refresh only parts of the page via ajax for a smoother feel. I tried using a “Javascript:FunctionHere()” instead of the custom URL and it wasn’t happy about it. But this is a small issue.