BNDragon helped me last week to create a form which enable a registred user to insert, save and update data. My project was to create some checklists which each registred user can use, but with the limitation that a user can only create one record per form.
You will find attached to this topic a PDF file called CHRONOFORM FORM which explain precisely how BNDragon solved the issues I had.
You will also find a backup of this form, which you can use. But don't forget to adapt it and to create your database.
I hope it helps !
Thanks to BNDragon !
If your main question got answered then please mark the answer using the button!
Hi, and thank you for such a great and detailed guide I have a question though from trying to adapt it to fit my own form. Not sure if I should start a new thread or post here, but here it goes.
I'm at the "custom code action" (on found) under the DB Read /On Load. The last few lines of php code seem to deal with reading data from the checkbox entries, but since I'm no php programmer I'm really struggling to adapt this to my case where I have two text boxes instead of checkboxes that I would want to read/save data from.
What are the lines of code you need help with ?
Hi, and thanks for the quick reply
$checkbox1=$line['checkbox group name'];
$pieces = explode(",", $checkbox1);
$form->data["checkbox group name"] = $pieces;
$checkbox2=$line[‘checkbox group name'];
$pieces = explode(",", $checkbox2);
$form->data["checkbox group name"] = $pieces;
No, those lines just split the checkboxes values since they are normally a list of values, so if you don't have checkboxes in your form then this is not helpful!
I'm sorry to ask again, but I can't seem to get this working. Am I wrong thinking that the custom code (which the above code was a part of) under On load/DB Read/On found handles the displaying of the found DB entries in the website form? If thats the case then my question is how can I insert my two textbox values in the website form instead of the checkbox ones in the example? Simply changing the checkbox1 and checkbox2 values don't seem to work. Since the only mention in the code of the saved form values are in the code above, I assumed they had to do with the inserting of the read DB values into the website form.
Your problem is in the "save" part or the update part ?
the save part should be straight forward, a "DB Save" will handle this.
The update part should be the same, but you will have to set the primary key value in the "data array" before the "db save", you can read the data using a "db read" action.
You should not have to worry about any fields values in this process.
Ok, so I've installed the backup form that goes with the PDF guide and I got it to work with the checkboxes, just to try it as it is before trying to make it fit my own purpose.
To the example form I've then added a "text13" textbox to the designer and made a new table which includes this field as well. The form updates the DB just fine, but the strange ting is that the saved value to text13 remains visible in the textbox when changing users and even with no users logged in. The checkboxes changes values as they should.
The other strange thing is that the form only seem to save a record for the first user that submits the form. Any other users logging in doesn't get its own DB entry from submitting the form. Is there anything I've missed, and mabye even a connection between the two?
I think I may have solved the first problem myself by adding the following code at the end of both custom code entries and now the saved values loads only when logged in for the textbox as well.
$form->data["text13"] = $typetb;
I'm at the point now where I've done some reading and understand that the update/save to DB for different users have to do with the primary key setting when creating the table (like you correctly mentioned in your last post), but I can't figure out which column that should be set as primary key. By default when creating a table a INT "id" column with extra set to "auto_increment" is suggested. I've tried removing the "auto_increment" setting, since I believe that the "id" column should contain the user id, and not an auto incremented number, but this doesn't seem to help. I've also tried setting "user_id" as primary key.
The table's primary key should be id and it should be set to auto increment, there is already another column created by default named "user_id", and that one will hold the user's id (if a user is logged in), this also happens automatically if you have the latest v5 update.
Please try creating a new fresh form with a new table and test this, each submission should then store a new record.
Let me know!
Ok, thank you for the clarification on the table settings. I've now tried setting up a new form with a table from scratch, using the basic setup from the example files to produce the functionality that I'm after. Still not able to create a new record for other than the first user that submits the form. That user updates the corresponding record when new data is submitted (which is correct), but data from any other than the first user that submits doesn't register anywhere.
I tried removing the update condition code below from the DB Save under On submit. When I do that there's created a new record each time someone submits the form, but this way already submitted data from registered users aren't updated, just a new record created for each submission. Could there be something with this update condition code that prevents a new record from being created for new users?
return array("user_id" => $form->data["userID"]);
Well, if you have the code above in the "update conditions" then the logged in user's record will always be updated, so, if you are submitting the form without being logged in then you will have a record with user_id = 0, and that record will be always updated.
Please try to login using 2 different users and submit the form each time, do you get 1 record or 2 records ?
2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com