Tell us what you are trying to do?
- I have a custom post type called 'Reference'
- I have a User Role of 'Customer' and also a linked Custom Post Type of 'Customer' (the CPT is to allow me to store extra data on the Customer which I cannot store within the User profile). The 'post title' of the Customer 'Post' is the email address which the Customer 'User' signs in with. This is all fine so far.
- I have a 'Relationship' set up between 'Customers' and 'References' (a one-to-many relationship, so a Customer can input multiple References).
- On my site, 'Customer' users log in, and then they can input a 'Reference' (as long as they have at least 1 credit, but that credit part is not relevant to this thread, it's just for information purposes).
- When inputting a 'Reference', the Post Form on the front end has the Relationship field (customer-reference is the slug) setup as part of the Form, and as mentioned above, the Customer has to be logged in in order to access this form.
So, what I want to achieve is, for the value of the Relationship field 'customer-reference' to be pre-populated in my Post Form for 'Reference', with the logged in Customers email address. To try to achieve this, I input the following code into my 'Reference' Post Form:
[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'customer' )"]
[cred_field field='@customer-reference.parent' class='form-control' output='bootstrap' required='true' author='$current' select_text="[wpv-current-user info='email']" value="[wpv-current-user info='email']"]
[/wpv-conditional]
However, although this 'appears' to work, it actually does not. I will explain:
- When the form first loads up, the email address indeed 'appears' to be pre-populated in the relationship field (please see attached image '1-form-loads.jpg'). The logged in user email address is in the field, but it does look 'greyed out'.
- Then when I click to submit the form, the form does not submit, and instead my Relationship field displays an error message of 'this field is required', suggesting that the field is in fact empty, even though the email address is showing in there (please see attached image '2-submit-form-but-field-is-not-populate.jpg').
- So I then have to click on the dropdown box (for the customer-reference field), where I am given the email address to click and select, after which the value shows again, but this time it is not 'greyed out' (for this part, I recorded a quick screencast, which you can view on this link = hidden link). After doing this, this time when I click the submit button, the form submits.
So, my question is, how do I get the Relationship field 'customer-reference' to be pre-populated AND selected with the value of the current logged in user email address please? If you could also explain why the code I have used does not work properly (just so I can understand better) that would be great 🙂
Thanks in advance for your help,
Keith
Is there any documentation that you are following?
I could not find any documentation explaining how to do this
Is there a similar example that we can see?
No
What is the link to your site?
It's under development, I can provide a private link (and login credentials) if you need it, in a private window please 🙂