Closed dbrown199747 closed 1 month ago
Just updated to the latest version of the API and it works. Thanks :)
Hi @engram-design, this is still an issue. I am on Craft 4.9.5, Formie 2.1.16. The entries are being overriden instead of new ones created. We use 1 form to add or edit locations, and either prefill the form with values or leave the form completely empty. There is a hidden field locationId that will be empty for new locations, or prefilled when we edit a location.
When I look in my submission data, I can see that the locationId remains empty, also in the formie log in the $_POST variable I can see it's empty. I've added a screenshot of the setup.
I can see you're using "Location ID" as the field to check against an existing entry for. This value is compared to the Entry ID (the element ID).
Firstly, Location ID is a Hidden field, correct? Are you mapping that in the "Attribute Mapping" setting? Are you using the correct ID - what's an example value you're using? Does that match with an existing Location entry?
Hi @engram-design , the location ID is indeed a hidden field. This is indeed either an Entry ID or an empty value.
Below is our code where we can prefill it:
{% do craft.formie.populateFormValues(form, { locationAccessibility: { locationHasDisabledParking: location.locationHasDisabledParking, locationHasDisabledToilet: location.locationHasDisabledToilet, locationHasParkingBicycles: location.locationHasParkingBicycles, locationIsWheelchairAccessible: location.locationIsWheelchairAccessible, }, locationAddress: { locationAddressCity: location.locationAddressCity, locationAddressNumber: location.locationAddressNumber, locationAddressPostcode: location.locationAddressPostcode, locationAddressStreet: location.locationAddressStreet, }, locationClosingPeriods: location.locationClosingPeriods, locationDescription: location.locationDescription, locationEmail: location.locationEmail, locationExternalLink: location.externalLink, locationExtraInformation: location.locationExtraInformation, locationId: location.id, locationImages: location.locationImages.ids(), locationMap: { locationCoordinateLat: location.locationCoordinateLat, locationCoordinateLng: location.locationCoordinateLng, locationMapUrl: location.locationMapUrl, }, locationName: location.title, locationServices: location.locationServices.ids(), locationTel: location.locationTel, locationType: location.locationType.ids(), locationOpeningHours: [ { 0: location.locationOpeningHours[0]['maandag'], 1: location.locationOpeningHours[0]['dinsdag'], 2: location.locationOpeningHours[0]['woensdag'], 3: location.locationOpeningHours[0]['donderdag'], 4: location.locationOpeningHours[0]['vrijdag'], 5: location.locationOpeningHours[0]['zaterdag'], 6: location.locationOpeningHours[0]['zondag'] }, ], locationClosingHours: [ { 0: location.locationClosingHours[0]['maandag'], 1: location.locationClosingHours[0]['dinsdag'], 2: location.locationClosingHours[0]['woensdag'], 3: location.locationClosingHours[0]['donderdag'], 4: location.locationClosingHours[0]['vrijdag'], 5: location.locationClosingHours[0]['zaterdag'], 6: location.locationClosingHours[0]['zondag'] }, ], locationHasSecondTimeSlot: location.locationHasSecondTimeSlot, locationSecondOpeningHours: [ { 0: ( 'locationHasSecondTimeSlot' in location and 'locationSecondOpeningHours' in location and location.locationSecondOpeningHours is not null ? location.locationSecondOpeningHours[0]['maandag'] : '' ), 1: ( 'locationHasSecondTimeSlot' in location and 'locationSecondOpeningHours' in location and location.locationSecondOpeningHours is not null ? location.locationSecondOpeningHours[0]['dinsdag'] : '' ), 2: ( 'locationHasSecondTimeSlot' in location and 'locationSecondOpeningHours' in location and location.locationSecondOpeningHours is not null ? location.locationSecondOpeningHours[0]['woensdag'] : '' ), 3: ( 'locationHasSecondTimeSlot' in location and 'locationSecondOpeningHours' in location and location.locationSecondOpeningHours is not null ? location.locationSecondOpeningHours[0]['donderdag'] : '' ), 4: ( 'locationHasSecondTimeSlot' in location and 'locationSecondOpeningHours' in location and location.locationSecondOpeningHours is not null ? location.locationSecondOpeningHours[0]['vrijdag'] : '' ), 5: ( 'locationHasSecondTimeSlot' in location and 'locationSecondOpeningHours' in location and location.locationSecondOpeningHours is not null ? location.locationSecondOpeningHours[0]['zaterdag'] : '' ), 6: ( 'locationHasSecondTimeSlot' in location and 'locationSecondOpeningHours' in location and location.locationSecondOpeningHours is not null ? location.locationSecondOpeningHours[0]['zondag'] : '' ) }, ], locationSecondClosingHours: [ { 0: ( 'locationHasSecondTimeSlot' in location and 'locationSecondClosingHours' in location and location.locationSecondClosingHours is not null ? location.locationSecondClosingHours[0]['maandag'] : '' ), 1: ( 'locationHasSecondTimeSlot' in location and 'locationSecondClosingHours' in location and location.locationSecondClosingHours is not null ? location.locationSecondClosingHours[0]['dinsdag'] : '' ), 2: ( 'locationHasSecondTimeSlot' in location and 'locationSecondClosingHours' in location and location.locationSecondClosingHours is not null ? location.locationSecondClosingHours[0]['woensdag'] : '' ), 3: ( 'locationHasSecondTimeSlot' in location and 'locationSecondClosingHours' in location and location.locationSecondClosingHours is not null ? location.locationSecondClosingHours[0]['donderdag'] : '' ), 4: ( 'locationHasSecondTimeSlot' in location and 'locationSecondClosingHours' in location and location.locationSecondClosingHours is not null ? location.locationSecondClosingHours[0]['vrijdag'] : '' ), 5: ( 'locationHasSecondTimeSlot' in location and 'locationSecondClosingHours' in location and location.locationSecondClosingHours is not null ? location.locationSecondClosingHours[0]['zaterdag'] : '' ), 6: ( 'locationHasSecondTimeSlot' in location and 'locationSecondClosingHours' in location and location.locationSecondClosingHours is not null ? location.locationSecondClosingHours[0]['zondag'] : '' ) }, ], locationHasThirdTimeSlot: location.locationHasThirdTimeSlot, locationThirdOpeningHours: [ { 0: ( 'locationHasThirdTimeSlot' in location and 'locationThirdOpeningHours' in location and location.locationThirdOpeningHours is not null ? location.locationThirdOpeningHours[0]['maandag'] : '' ), 1: ( 'locationHasThirdTimeSlot' in location and 'locationThirdOpeningHours' in location and location.locationThirdOpeningHours is not null ? location.locationThirdOpeningHours[0]['dinsdag'] : '' ), 2: ( 'locationHasThirdTimeSlot' in location and 'locationThirdOpeningHours' in location and location.locationThirdOpeningHours is not null ? location.locationThirdOpeningHours[0]['woensdag'] : '' ), 3: ( 'locationHasThirdTimeSlot' in location and 'locationThirdOpeningHours' in location and location.locationThirdOpeningHours is not null ? location.locationThirdOpeningHours[0]['donderdag'] : '' ), 4: ( 'locationHasThirdTimeSlot' in location and 'locationThirdOpeningHours' in location and location.locationThirdOpeningHours is not null ? location.locationThirdOpeningHours[0]['vrijdag'] : '' ), 5: ( 'locationHasThirdTimeSlot' in location and 'locationThirdOpeningHours' in location and location.locationThirdOpeningHours is not null ? location.locationThirdOpeningHours[0]['zaterdag'] : '' ), 6: ( 'locationHasThirdTimeSlot' in location and 'locationThirdOpeningHours' in location and location.locationThirdOpeningHours is not null ? location.locationThirdOpeningHours[0]['zondag'] : '' ) }, ], locationThirdClosingHours: [ { 0: ( 'locationHasThirdTimeSlot' in location and 'locationThirdClosingHours' in location and location.locationThirdClosingHours is not null ? location.locationThirdClosingHours[0]['maandag'] : '' ), 1: ( 'locationHasThirdTimeSlot' in location and 'locationThirdClosingHours' in location and location.locationThirdClosingHours is not null ? location.locationThirdClosingHours[0]['dinsdag'] : '' ), 2: ( 'locationHasThirdTimeSlot' in location and 'locationThirdClosingHours' in location and location.locationThirdClosingHours is not null ? location.locationThirdClosingHours[0]['woensdag'] : '' ), 3: ( 'locationHasThirdTimeSlot' in location and 'locationThirdClosingHours' in location and location.locationThirdClosingHours is not null ? location.locationThirdClosingHours[0]['donderdag'] : '' ), 4: ( 'locationHasThirdTimeSlot' in location and 'locationThirdClosingHours' in location and location.locationThirdClosingHours is not null ? location.locationThirdClosingHours[0]['vrijdag'] : '' ), 5: ( 'locationHasThirdTimeSlot' in location and 'locationThirdClosingHours' in location and location.locationThirdClosingHours is not null ? location.locationThirdClosingHours[0]['zaterdag'] : '' ), 6: ( 'locationHasThirdTimeSlot' in location and 'locationThirdClosingHours' in location and location.locationThirdClosingHours is not null ? location.locationThirdClosingHours[0]['zondag'] : '' ) }, ], }, true) %}
I cannot map it in the attributes mapping, as I don't see the field there.
When I've selected a location, I can see via inspect that the hidden field is filled in.
When I want to create a new location, the hidden field remains empty, which is ok.
This is something that has been working, so I don't immediately see what could be wrong with the setup.
I think I see the issue here, in that if the Location ID is empty, it's actually going to just find the first available entry for that section/entry type. Where it should return a new entry as there's no value. Currently, there's just a check if you have anything mapped in the "Update Element Mapping" settings.
Fixed for the next release. To get this early, run composer require verbb/formie:"dev-craft-4 as 2.1.16"
.
Describe the bug
Whenever I use element mapping, it always replaces the most recent entry in the chosen channel instead of adding a new entry. I have a screen recording below best describing this. I would like to add new entries from the front end into a channel as and when I want to, but it just replaces the current entry. I've checked the documentation and can't see what i'm doing wrong.
View screen recording: https://we.tl/t-1uzyGippX0
Steps to reproduce
Form settings
Craft CMS version
Craft Pro 4.8.8
Plugin version
Multi-site?
No
Additional context
No response