Forums

How to resolve 'Data save failed' on form submission?

Hannon 09 Mar, 2022
As a beginner, I'm attempting to design a form that would add a new record to a database, but can't. On pressing Submit, with debug set, I get the message 'Data save failed'. Looking through the page HTML, the form action says <form action="....chronoform=add_user&amp;gpage=new_page_2" instead of ending event=submit, which I guess is a clue.

Based on another thread here, I note that the Save Data action is supposed to be on the page after the submit button, so I do have two pages, but the data seems to be falling through the gap.

Any clues as to what I've missed would be cool.
Colnem 10 Mar, 2022
Hi

You have to use 2 pages.
Your form have to be in start page.
End of your start page: a submit button redirecting on end page (by Choose next page).
First, at the beginning of end page, please, just add an Action message to see your datas: {data.pr:}
If it's good, replace Action Message by Action Save Datas, choose your table, mode Insert only.
If it doesn't work, use Debug mod and look at your sql request...

In what table are you saving your datas? A new Table? Is this table created?

Bye
Hannon 10 Mar, 2022
Thanks for you help Colnem!

Going through your checklist:
  1. Yes, I'm using 2 pages
  2. The end of the start page does have a submit button, submitting to page 2 (that is to 'form.new_page_2' as I've not changed the defaults)
  3. I've added {data.pr:} to the end of the 2nd page, and an array showing the data is returned (good to know the data is reaching the 2nd page!)
  4. Replacing the action message by the Action 'Save Data', including choosing the table and with mode 'Insert new Record' doesn't save the data.
  5. In debug mode I don't see an SQL request; I get this:
Array
(
    [option] => com_chronoforms7
    [cont] => manager
    [chronoform] => add_user
    [gpage] => new_page_2
    [Users] => Array
        (
            [user] => Test
            [day_of_the_week] => Mon
            [day_of_the_week_again] => 1
            [frequency] => Weekly
            [time_start] => 01:00
            [time_end] => 02:00
            [rooms] => Main Hall
            [entry] => Join up
            [cost] => 1
            [contact_name] => Test
            [contact_phone] => 0123456789
            [contact_email] => 
            [contact_url] => 
            [committee_rep] => 
            [published] => 1
        )

    [__cf_token] => c482ee2e-dab9-4595-b954-f74acdd5a654
)
Array
(
    [save_data_28] => Array
        (
            [result] => Data save failed!
            [dataset] => Array
                (
                    [option] => com_chronoforms7
                    [cont] => manager
                    [chronoform] => add_user
                    [gpage] => new_page_2
                    [Users] => {"user":"Test","day_of_the_week":"Mon","day_of_the_week_again":"1","frequency":"Weekly","time_start":"01:00","time_end":"02:00","rooms":"Main Hall","entry":"Join up","cost":"1","contact_name":"Test","contact_phone":"0123456789","contact_email":"","contact_url":"","committee_rep":"","published":"1"}
                    [__cf_token] => c482ee2e-dab9-4595-b954-f74acdd5a654
                )

            [log] => Array
                (
                    [0] => false
                )

            [var] => false
        )

)

The data should be saved into an existing custom table that already has data in it - and I have selected that table in as the 'Target Table' in 'Save Data'.


...So I'm puzzled.
Colnem 10 Mar, 2022
1 Likes
Hi
Your datas sounds to be in an array. YOu would have:
 Array
(
[option] => com_chronoforms7
[cont] => manager
[chronoform] => add_user
[gpage] => new_page_2
[user] => Test
[day_of_the_week] => Mon
[day_of_the_week_again] => 1
[frequency] => Weekly
[time_start] => 01:00
[time_end] => 02:00
[rooms] => Main Hall
[entry] => Join up
[cost] => 1
[contact_name] => Test
[contact_phone] => 0123456789
[contact_email] =>
[contact_url] =>
[committee_rep] =>
[published] => 1
[__cf_token] => c482ee2e-dab9-4595-b954-f74acdd5a654
)

If you wish your datas in an Array (Users), don't use Whole Datas, but Add field. Syntax to save your fields is (if datas names are the same than table fields name):

field name: user value {data:Users.user}
and so on...
Hannon 11 Mar, 2022
Answer
Thank you Colnem - that was the clue I needed.

I added a Data Source under 'Save Data' -> 'Advanced Settings' and added the filed names just as as you said. And after deleting the line for cf_id, so that the database handled the auto-increment, it worked🙂

Although I'm now stuck on how to restrict the form to registered users - I've just started another thread on that:
How to restrict visibility and use of the form to logged-on users?
You need to login to be able to post a reply.