Skip Navigation

[Résolu] Strange error submitting form, field emptied, dropdown empty

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I am seeing a validation error when trying to submit a Form to create a post on a multilingual site, "An error occurred when creating an association"

Solution: Update to the latest version of our plugins.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 1.43 hours from now. Thank you for your understanding.

This topic contains 16 réponses, has 2 voix.

Last updated by Dido Il y a 3 années.

Assigned support staff: Christian Cox.

Auteur
Publications
#922170
Empty Country.PNG

I am trying to: Test a form to create a custom post type related to a country (which is in another CPT).

Link to a page where the issue can be seen: Sorry, form hidden when not logged in.

I expected to see: Form succesfully submitted.

Instead, I got: Strange error submitting form (cf. screenshot), the content of the first field was lostand the country could not be entered again (empty dropdown list). It worked before. What does the error message mean? Could the message be made clearer?

#922280

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Hi, the error message is related to translations. It says the User is trying to create a post in a secondary language without first creating the default language post, or perhaps the User is trying to create a post that is related to another post in a secondary language, but the default language related post does not exist yet. It is probably related to the new WPML translation fallback options, but I need some more information.
- What post type or post types are involved?
- What relationships exist between these post types?
- What are the translation settings in WPML for these post types?
- What are the primary and secondary languages for this site, and is the problem occurring on all languages?

#923062

You are correct that the error message was related to translations. We made one of the custom posts translatable (although it was already set to English, which is the default language) and the error disappeared. What did not disappear, however, was that, if for some other reason an error appeared, some fields, like dates and country (selected from another custom post) were reset (became empty). Is there no way to keep everything that has been entered? As this seems to be a generec problem, do you still need details about our custom posts and relationships?

#923175

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Can you copy + paste all the code from this Form here for me to review? I would like to see how everything is configured.

#923449

Hi Christian, we use the following CRED form to create a draft custom post called "House". We then need the author (who does not have an account yet) to edit this post, so as to add a number of connections to another custom post called "country". These connections represent the countries in which the house owner is willing to do a house swap. Adding connections does not seem to be possible when the "house" post has not yet been submitted. We assumed it would be possible to enter one country (the house owner's own country of residence) using the "new house" form, as no intermediate custom post is required for such a relationship, but even that proves difficult as the country does not seem to be saved. That piece of code was temporarily removed from the form below. So we have a number of problems here, unfortunately. First creating an account is not what the client wants. From a commercial point of view I can understand that. In the mean time I will keep experimenting with ways to jump to the edit form. Do I need to fill in something in the urlparam of the form_submit? Or should passing the right post-id be handled by specifying in the settings of the form that on submit, we should jump to a specific page, namely the one containing the edit form? The latter is how I have tried it, but I have tried other things as well.

[credform class='cred-form cred-keep-original']

<div class="form-group">
<label>Please specify the city or town where your property is located.</label>
[cred_field field='post_title' urlparam='post_title' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Please indicate on this map the exact location of your property</label>
<p>The property will apear on the map without address.</p>
[cred_field field='address' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>What is the period of the assignment</label>
[cred_field field='start-date' class='form-control' output='bootstrap']

<label>Is this start date flexible?</label>
[cred_field field='start-flex' output='bootstrap']
</div>
<div class="form-group">
<label>End date</label>
[cred_field field='end-date' class='form-control' output='bootstrap']

<label>Is this end date flexible?</label>
[cred_field field='end-flex' output='bootstrap']
</div>

<div class="form-group">
<label>What is the period of the assignment</label>
[cred_field field='start-date-search' value='' urlparam='' class='form-control' output='bootstrap']
<label>Is this start date flexible?</label>
<label>Start date</label>
[cred_field field='start-flex-search' output='bootstrap']
</div>
<div class="form-group">
<label>End date</label>
[cred_field field='end-date-search' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Is this end date flexible?</label>
[cred_field field='end-flex-search' output='bootstrap']
</div>
<div class="form-group">
<label>What activities and experience are absolutely required of the temporary occupants?</label>
<p>Pet Care</p>
[cred_field field='pet-care' value='' urlparam='' output='bootstrap']
Other, namely[cred_field field='other-pet' value='' urlparam='' class='form-control' output='bootstrap']
<p>Animal Care</p>
[cred_field field='animal-care' value='' urlparam='' output='bootstrap']
Other, namely[cred_field field='other-animal' value='' urlparam='' class='form-control' output='bootstrap']
<p>General</p>
[cred_field field='general' value='' urlparam='' output='bootstrap']
Other, namely[cred_field field='other-general' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>What can you offer with your property? Please indicate.</label>
[cred_field field='offer' value='' urlparam='' output='bootstrap']
Sleeping capacity, please specify [cred_field field='sleeping-capacity' value='' urlparam='' class='form-control' output='bootstrap']
Number of bathrooms, please specify [cred_field field='number-of-bathrooms' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Please indicate if the following is available:</label>
[cred_field field='available-he' value='' urlparam='' output='bootstrap']
<p>Heating, namely:</p>
[cred_field field='heating-type' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Please indicate if the following is required:</label>
[cred_field field='available' value='' urlparam='' output='bootstrap']
</div>
<label>You can upload 1 main photo and 6 additional photos in JPEG (JPG) format
with a maximum of 3 MB per photo.</label>
<p>The photos will be automatically resized down to fit. If you have any problems with downloading, please check whether the photos are in the right format before uploading them</p>
[cred_field field='default-photo' value='' urlparam='' output='bootstrap']
<label>Additional photos</label>
[cred_field field='additonal-1' value='' urlparam='' output='bootstrap']
[cred_field field='additonal-2' value='' urlparam='' output='bootstrap']
[cred_field field='additonal-3' value='' urlparam='' output='bootstrap']
[cred_field field='additonal-4' value='' urlparam='' output='bootstrap']
[cred_field field='additonal-5' value='' urlparam='' output='bootstrap']
[cred_field field='additonal-6' value='' urlparam='' output='bootstrap']
<div class="form-group">
<label>House Content</label>
<p>You can create your property advertisement in the following format, using a maximum of 6,000 characters (spaces included).</p>
[cred_field field='post_content' output='bootstrap']
</div>
<div class="form-group">
<label>Subtitle</label>
<p>With a maximum of eight words.</p>
[cred_field field='subtitle' output='bootstrap']
</div>
<div class="form-group">
<label>What I expect of house occupants.</label>
[cred_field field='expect-occupants' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Description of the property</label>
[cred_field field='post_excerpt' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Good to know about this assignment.</label>
[cred_field field='good-to-know' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Why choosing this property?</label>
[cred_field field='why-choosing' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>What name do you want to use on this website, not being your login name?</label>
[cred_field field='display-name' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>You can make a telephone number visible, if you wish.</label>
[cred_field field='telephone-number-visible' value='' urlparam='' output='bootstrap']
<p>Please enter your telephone number, including your country code.</p>
[cred_field field='telephone-number' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<p>Would you like to receive a daily alert via email about the most recent house-exchange possibilities that match your preferences?</p>
[cred_field field='daily-alert' value='' urlparam='' output='bootstrap']
</div>
<div class="form-group">
<label>Do you have any evaluation?</label>
[cred_field field='have-evaluation' class='form-control' output='bootstrap']
<p>Please add your evaluation with the option to add one photo per evaluation.</p>
<p>You can enter your text with a maximum of 3,000 characters (spaces included) and it is possible to upload a photo with a maximum of 3MB and in a JPEG (JPG) format.</p>
[cred_field field='evaluation' value='' urlparam='' output='bootstrap']
<p>The photo will be automatically resized down to fit. If you have any problems with downloading, please check whether the photo is in the right format before uploading.</p>
[cred_field field='evaluation-photo' value='' urlparam='' output='bootstrap']
</div>
[cred_field field='form_messages' value='' class='alert alert-warning']
[cred_field field='form_submit' value='Next page' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[/credform]

#923706

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Adding connections does not seem to be possible when the "house" post has not yet been submitted.
Yes, that is correct. Post IDs are required to create relationship connections, so if the House post has not been submitted yet it doesn't have an ID.

We assumed it would be possible to enter one country (the house owner's own country of residence) using the "new house" form, as no intermediate custom post is required for such a relationship, but even that proves difficult as the country does not seem to be saved.
We are aware of an issue related to creating new child posts in a one-to-many relationship, and when Layouts or redirects are involved sometimes parent posts aren't being saved correctly. I have a code-based workaround for this until the bug is resolved, so please create a separate ticket to discuss that in more detail if you need more information. Here's a similar ticket about that with the code:
https://toolset.com/forums/topic/difficulty-storing-related-post/page/2/#post-913651

Or should passing the right post-id be handled by specifying in the settings of the form that on submit, we should jump to a specific page, namely the one containing the edit form?
I think you'll need the cred_success_redirect API hook: https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
This will allow you to redirect programmatically, and you will have access to the new post's ID in the callback. If you have further questions about that, please create a new ticket and we can discuss in more detail.

#924214

Hi Christian, I added the two pieces of custom code to the child theme's functions.php and I will create new tickets if I need further help with those. However, the original error is back, which is: "An error occurred when creating an association: The default language version of an element involved in an association is missing." This is connected to reinstating the following important piece of code in the CRED form: [cred_field field='@country-offered.parent' select_text='--- niet ingesteld ---' class='form-control' output='bootstrap']. This is generated when I insert a form field of type "relationship", pointing to the parent custom post type "house". Note that I can easily connect a house to a country via the dashboard, but not via this CRED form. So if a language setting is actually missing, how come the error does not occur when doing this via the dashboard? I also want to urge the developpers to make the error message clearer. It would help tremendously if it would be clear which "element" in which association is missing!

#924369

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Okay thanks for the information. There are lots of moving pieces so I think it's best if I can create a clone of your website to try to reproduce the issue locally. If that's okay, please provide login credentials in the private fields here.

#947882

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Okay I'm not able to see anything obviously wrong here. In my clone of the site, I created a new Form and ran into several other error messages. I'm asking my 2nd tier support team to take a closer look, and I have provided them with a copy of the site. I'll let you know what I find out as soon as possible.

#955691

Is there any progress or news regarding the form? We like to get this working, as it prevents us from further development and testing. Our client is getting restless and there is still a lot of development to do. By the way, is one of the errors you are getting a 404 trying to transition to the next page? This error seems to be new with the latest update of types?

#955709

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Hi, I can see that my 2nd tier team has escalated this to our Forms developers as an exception, and we are waiting to receive some feedback from their investigation. I'll let you know as soon as possible if I receive any new information about the ticket.

#1083956

Hi, Is there any progress on this issue? It is not easy to work on the further development of the website when this is not solved.

#1083969

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Hi, I'll ask my 2nd tier team to check in with the developers but as yet I have not seen any new information about this issue.

#1090230

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Hi, our developers have let me know the fix for this issue will be included in Forms 2.1. I'll keep you posted here when I learn about the delivery of this upcoming version.

#1099565

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Hi, please find Forms 2.1 avaialable for download or automatic update. This version of the plugin includes a permanent fix for this issue. Let me know if the problem is not fully resolved in Forms 2.1.