Buy Now
Sign in

Form creates new record instead of updating existing one dis

peterswa62 , October 01 2012
P
peterswa62
I am using version 4 of Chronoforms. I have a form which loads a record for editing using DB Load Recorder and various fields. I have draggged on the On Submit event the DB Save function and set it to the right table and Model ID, but instead of updating the existing record it creates a new one.What am I missing out?
GreyHead
Hi peterswa62 ,

You need to make sure that the primary key of the record you are editing is included in the form data. Usually you do this by adding it in a hidden input.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
P
peterswa62
It still doesn't work! I've set the DB Field of the DB Record Loader to id:- the primary key of my table. Set the name of a hidden field to id on the form. Is there another way of doing this?
GreyHead
Hi peterswa62 ,

Is the value of the hidden input set correctly? i.e. does it pick up the primary key value?

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
P
peterswa62
The Field Name and Field Id are set to "id" the name of my primary key in the table. The Field Value is set to "2" to test it on updating this record with this primary key. Is this right?
P
peterswa62
How do you set the Hidden Field exactly?
GreyHead
Hi peterswa62,

Drag a Hidden element into the Form Preview box.

Set the name to id

For testing you can hard code a value in the Value option box.

For production leave the Value box empty and maker sure that there is a value of id set in the $from->data array - loaded from a DB Record Loader, added to the URL, passed from a previous form page, set up in a Custom Code action, any of these will work.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
P
peterswa62
Sorry to be a nuisance but it still doesn't work all I get is a blank form when I do what you say.

However when I put id = 2 in the WHERE clause on DB Record Loader it correctly loads the record with this primary key, but when you save it creates a new record. When I set the hidden field value to 2 and the WHERE clause to blank:- nothing.

For some reason it cannot see the hidden field which I have put on the form. Is it to do with the version:- I am using the latest version of Chronoforms v4. Is it to do with the hidden elememt? I am using something called Hidden Box which I dragged from advanced elements tab. Is it a wrong setting with DB Record Loader? Is it a wrong setting with with DB Save? Is it a bug? I cannot figure it out.
GreyHead
Hi peterswa62,

Please do View Source on the form and see if the hidden input is correct and is inside the <form> tags - it should be.

Please drag a Debugger action into the On Submit event, then submit the form and post the debug results here.

Note: if you are using the Easy Wizard you can turn on Debug on the Others tab.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
P
peterswa62
Hi I checked the source code like you said and the hidden field is there before the form tag alongside another hidden field presumably created by ChronoForms :-
<input type="hidden" value="2" name="id" />
<input type="hidden" name="975c2f6bdd5fce206b794404ba5e8f20" value="1" />
</form>


I put A Debugger on the submit action with the hidden field setting id to 2 to load this record and I have Model Id called client in DB Record Loader. When I press submit form and this is what I got:-

Array
(
[option] => com_chronoforms
[chronoform] => ViewClient
[event] => submit
[Itemid] =>
[client] => Array
(
[cf_uid] => ff87f0b004f09c2dd337e80b948ff0f7
[cf_created] => 2012-10-05 06:53:29
[cf_created_by] => 0
[cf_ipaddress] => 109.153.116.68
[cf_user_id] => 0
[title] =>
[firstname] =>
[middlename] =>
[lastname] =>
[address1] =>
[town] =>
[county] =>
[postcode] =>
[NI_No] =>
[datestarted] =>
[telephone] =>
[telephone2] =>
[email] =>
[ref] =>
[company] =>
[authentication_code] =>
[status] =>
[status2] =>
[Reg_No] =>
[PAYE_Ref] =>
[VAT_No] =>
[year_end] =>
[account_due] =>
[next_annual_return] =>
[price_for_year] =>
[account] =>
[account_return] =>
[notes] =>
[id] => 125
)

[address2] =>
[update_client] => Submit
[id] => 2
[975c2f6bdd5fce206b794404ba5e8f20] => 1
[client_id] => 125
)
Validation Errors:
Array
(
)
GreyHead
Hi peterswa62,

It looks form this as though the id of the record being edited is 125 so You'd need to have that in the hidden input to save to the same record???

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
P
peterswa62
I put id = 2 in the hidden field and it set the id to 125. There are 123 records in the database so its just creating a new record in the database.
GreyHead
Hi peterswa62 ,

I'm sorry but none of this makes any sense to me :-(

Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
GreyHead
Hi peterswa62,

Thanks for the form backup. I seem to have landlord666 restored OK - but the form has no DB Record Loader or DB Save actions as far as I can see.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
P
peterswa62
The DB Save and DB Record Loader were definitely in the form before back up.
GreyHead
Hi peterswa62,

And no sign of a hidden input either :-(

I'm afraid that it doesn't tell me much.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
GreyHead
Hi peterswa62,

I'm sorry that was my mistake - I was looking at the wrong form :-(

I think that a part of the problem is that you are using a ModelID. The name of the hidden input probably needs to take account of this and be client[id] - or something similar. See the notes under 'Load under Model ID' in the DB Record Loader.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
P
peterswa62
The way you showed me does not work with me at all:- updating a record with a hidden field. Rather than waste any more time I have reported this as a bug. The only other way of doing it as far as I can see is to put a custom code section on the on submit event and use PHP. Is that correct?
GreyHead
Hi peterswa62,

As I noted on your other post there is no bug here. The method I have shown you will work - provided that you adapt it to work with the other settings you have chosen.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
B
bijilal
Same problem here.
Created a form with three fields and save it as frm1.
1. When I go the front end I don't see any of the three fields
2. When I open the same form to edit and save, it is asking to enter a new form name.

I am struggling with this for the last few days and decided to post on the forum. Once I see the basics working I will see if I can buy a subscription.

Thanks
Bijilal