I have a single page that I’m working on. The page loads with a single Channel Form. I then submit this form with AJAX and load additional forms after the submission completes. I need to post the initial form because the secondary forms relate to the entry_id of the initial form. The initial form stays on the page after the secondary forms are loaded in case edits need to be made.
After posting the initial form, I update the entry_id hidden field of the initial form with the newly-created entry_id. I was hoping this would be enough to tell EE just to update the entry instead of creating a new one. However that didn’t work. So I tried appending (in addition to updating the entry_id) a hidden field to the initial form with a name of url_title and the value as the newly created url_title. This also didn’t work.
A new entry is created instead of updating the initial entry, which should be based on the entry_id and url_title I added to the hidden fields. Do I need to update additional fields or the action so EE knows to edit instead of create?
I’ll show the form data that gets posted below. The initial form followed by the secondary submission of the same form with updated hidden fields:
<!-- initial form post -->
RET:http://somesite.com/some/template
URI:some/template
return_url:
author_id:1
channel_id:29
entry_id:0
ACT:6
meta:EWzHyzxr2xDIB4v47ObS2YEtXmFbPkbbWbStg7Cc63eCY11yatkG3o4pb6huSYXf0bBe344g9fcQ4RUq1/3I4Y8YzKnR8oXwpc8NhddKmcgTDor4MTA7tzVhXg+c4xogvCk+S2H0jRvCU//NwmTEtUoZFV5yEKnjl1/zQo8wbZnvFDj/ggHZJR0JF7zWfehMPfDZrnOg0GZygWhz31guyYaZ1ZdLwxTo6lshavD4P4XcQ4F+ZWY0ZKsGuQYJ3AaTvN2o44H97etJ94tBn9dZPadLOdHo5Hc2VTOqZ61nfZy9duufvAnPAXv4HI1IkuKpMJbClmwImZYCdDxY7Q4FoMg4gbaCQQUWAp0ZgwncOAH6nEJfdLGxx5AgUWdSECHnFT6mYhYp5nOJT4qJ48Px6tk1K6BEKXurCLfAQvUMJCga/Fimy0nxNgwki4UMKjeHOyEN3lzONwTN2jOWFNaPx2saHaJhXb3kC2wpGzx8BIE0Z7gvo86C+5/je+EHpaVz
checkbox_fields:checkbox_field_1|checkbox_field_2
site_id:1
csrf_token:0ef87fe0137d978a305e8d42c5ad30a79a2ee508
title:Test<!-- secondary post -->
RET:http://somesite.com/some/template
URI:some/template
return_url:
author_id:1
channel_id:29
entry_id:1572 {!-- updated after initial submission --}
ACT:6
meta:EWzHyzxr2xDIB4v47ObS2YEtXmFbPkbbWbStg7Cc63eCY11yatkG3o4pb6huSYXf0bBe344g9fcQ4RUq1/3I4Y8YzKnR8oXwpc8NhddKmcgTDor4MTA7tzVhXg+c4xogvCk+S2H0jRvCU//NwmTEtUoZFV5yEKnjl1/zQo8wbZnvFDj/ggHZJR0JF7zWfehMPfDZrnOg0GZygWhz31guyYaZ1ZdLwxTo6lshavD4P4XcQ4F+ZWY0ZKsGuQYJ3AaTvN2o44H97etJ94tBn9dZPadLOdHo5Hc2VTOqZ61nfZy9duufvAnPAXv4HI1IkuKpMJbClmwImZYCdDxY7Q4FoMg4gbaCQQUWAp0ZgwncOAH6nEJfdLGxx5AgUWdSECHnFT6mYhYp5nOJT4qJ48Px6tk1K6BEKXurCLfAQvUMJCga/Fimy0nxNgwki4UMKjeHOyEN3lzONwTN2jOWFNaPx2saHaJhXb3kC2wpGzx8BIE0Z7gvo86C+5/je+EHpaVz
checkbox_fields:customer_payment_terms|customer_tax_status
site_id:1
csrf_token:0ef87fe0137d978a305e8d42c5ad30a79a2ee508
title:Test
url_title:test {!-- appended to form as hidden field after initial submission --}I took out all of the custom fields’ data to try and keep the post data as short as possible. So the form data is getting processed as I hoped it would, it’s just resulting in a new entry instead of edits to the existing one. What am I missing here?
Thanks
In case anyone comes across this later, the reason the secondary submission isn’t updating is because the “meta” hidden field needs to be updated as well. After speaking with EE support, they informed me the meta value is an encrypted string containing the settings for the form. So just updating the entry_id on the form isn’t enough, the meta value needs to be updated as well.
I ended up doing this with an additional template, that I access with an asynchronous call, that takes the newly-created entry’s id as a segment variable. All the template contains is a Channel Form tag pair with the entry_id parameter set to the segment variable representing the newly-created entry that needs to be updated.
The template creates a new form based on the entry_id that it’s passed, and from there I just grabbed the value of the meta hidden form field from the returned HTML and updated the initial form with that value. Once the entry_id and meta hidden fields on the form I want to update have been adjusted, the form can be updated as I wanted it to.
Could someone further explain if it’s even possible to update the meta field based on the ajax response? I’m doing something almost identical (using the channel form example to build off of), and I’m getting the
'You successfully added a new entry with entry_id '+data.entry_idalert, but the next time it auto-submits it creates yet another new entry instead of updating the one it just created.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.