FreewayTalk

4 replies to this thread. Most Recent

Richard Cacciato

6 Mar 2020, 4:12 pm

Easy way to post Freeway form data to a mySQL database

I’m trying to create a form in Freeway and capture the form data in a MySQL Database. I’m hoping (lazily) that there’s an easy way to do this. I’ve set up the form and applied the mySQL connect action. From what I can see, the mySQL connect action sets up the database connection and theoretically all I would need to do is have a post action to post the form data to the db. There is the MySQL Get Records action on ActionsForge https://actionsforge.com/actions/mysql-get-records but there’s no equivalent post action.

Hoping someone can point me in the right direction, and that it’s not too hard…

Thanks in advance.

waltd

7 Mar 2020, 1:57 am

I don’t know about easy, but take a look at this page of code: https://github.com/walterdavis/mini-active-record/blob/master/demo/index.php and tell me if it makes any amount of sense to you. What this page demonstrates is a simple messages form and handler. It uses the ActiveRecord programming pattern to manage the relationship between the code and the database.

Lines 19-23 define the model that stands for the messages. Line 21 sets up validations, requiring that the person enter their name and the message (named body in this schema) in order to save. Line 22 sets up those two fields as “writeable”.

Line 40 is where we start writing the form contents into the database. The check for $_POST[‘commit’] checks to see if the form was submitted (since that’s the name of the submit button, and it would only be in the $_POST array if the button was pushed). Line 41 takes whatever was submitted from the form and writes it to the model. The model then validates whatever was entered, and if it passes muster, it writes a new record into the database with the form values.

The rest of the code is there to either display errors to the user, or to show a success message, or to show all the successfully submitted messages.

This is all wrapped together into one page of code, mixing PHP and HTML, which is not how normal apps are written. It’s just a demo. If you were to build the form in Freeway, you could use the PHP Use Include Pages action https://actionsforge.com/actions/php-use-include-pages to insert the PHP code into the top of the page, so you’d have a little separation between layout and code.

So the test for “easy” here is how much sense does the code on this page make to you. If the answer is “none”, then I don’t have anything easier to show you. If it makes some small amount of sense, then you may find this framework useful. Back when I used to write PHP, I used it all the time, and it really makes wiring up a database to the rest of the page quite straightforward.

Walter

On Mar 6, 2020, at 11:12 AM, Richard Cacciato <[email protected]> wrote:

I’m trying to create a form in Freeway and capture the form data in a MySQL Database. I’m hoping (lazily) that there’s an easy way to do this. I’ve set up the form and applied the mySQL connect action. From what I can see, the mySQL connect action sets up the database connection and theoretically all I would need to do is have a post action to post the form data to the db. There is the MySQL Get Records action on ActionsForge https://actionsforge.com/actions/mysql-get-records but there’s no equivalent post action.

Hoping someone can point me in the right direction, and that it’s not too hard…

Thanks in advance.

Freeway user since 1997

http://www.walterdavisstudio.com

Richard Cacciato

7 Mar 2020, 2:45 am

Whoa. OK so I guess the answer is “no easy way“. I’ll wade through the code in a day or two to see if I can make heads or tails of it.

Thanks and enjoy the weekend.

Richard Cacciato

11 May 2020, 5:42 pm

Reviving this thread. I tried wading through the code Walter gave me but then came across this which seemed to be a bit more straightforward: https://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php

I created a MySQL Database then edited the insert.php script file to include the db connect statement and named the variables to match my form in Freeway.

It’s been a while though and I don’t recall where to invoke the script from the form. Is it set in the Name item in Item Output Settings for the form submit button?

This is what I’m referring to: https://postimg.cc/9Dw3hLh8

Back to Top

waltd

11 May 2020, 6:29 pm

In any form, the way you direct the output of the form to the server is in the Action property of the form. Page / Form Setup on a regular Freeway page-level form. If you’re using an Action to allow multiple forms on a single page, then this setting will be in the Action that you use to do that.

Walter

On May 11, 2020, at 1:41 PM, Richard Cacciato <[email protected]> wrote:

Reviving this thread. I tried wading through the code Walter gave me but then came across this which seemed to be a bit more straightforward: https://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php

I created a MySQL Database then edited the insert.php script file to include the db connect statement and named the variables to match my form in Freeway.

It’s been a while though and I don’t recall where to invoke the script from the form. Is it set in the Name item in Item Output Settings for the form submit button?

This is what I’m referring to: https://postimg.cc/9Dw3hLh8

Freeway user since 1997

http://www.walterdavisstudio.com