I created an ACF post type named "Profile"
I want logged in users to be able to fill out their own profile and edit it via Fluent Form.
A user only has one "Profile" post content, so when he goes to the Fluent Form linked to the ACF "Profile" content, he either creates a new post if he does not have one , or it updates its existing information.
So I use "Post/CPT Creation" with a Post Feed.
If I use Submission Type "New Post", one user can create multiple profile (it’s not what I want)
If I use Submission Type "Update Post" the content is not created. Maybe I need to create 2 Post Feed on "New Post" and another "Update Post". I don’t understand well…
I’ve also tried the "Post Update" field but as each user only has one post, I find that it makes no sense to ask them to select their profile in this select. (even if I limit the field with its userid)
Is there a way to have a form that if a user don’t have any Profile he can create it. And if he already have a profile the form will load its information to allow hime to update it.
I have de PHP / Javscript Dev so I can use snippets (function.php) if this is a solution.
Thanks
Samuel
2
Answers
Thanks a lot Ibrahim Mustafa !
Your solution was good but the fluentfilter have changed
Here is my solution :
Step 1: Determine if the User Has a Profile Post
}
Step 2: Create/Update Post Based on User Status
Now, you’ll need to use Fluent Forms to determine if the user should create a new post or update an existing one. You can use the "Conditional Logic" settings within the form to achieve this.
Create a Hidden Field for User Profile Check:
Add a hidden field to your form and set its default value using the shortcode [user_has_profile] (adjust the shortcode based on your implementation).
Set Conditional Logic for Creating/Updating:
For the fields related to the profile information, set conditional logic to show them if the hidden field value is equal to "false" (indicating the user does not have a profile).
For the same fields, set another set of conditional logic to show them if the hidden field value is equal to "true" (indicating the user has a profile).
Create/Update Post Actions:
For the "Submit" or "Update" button, use Fluent Forms’ Post Feed to create or update the post based on the conditional logic.
For the "Post Feed" associated with creating a new post, set the condition to run when the hidden field value is equal to "false".
For the "Post Feed" associated with updating a post, set the condition to run when the hidden field value is equal to "true".
Step 3: Implementing the Hidden Field Logic
Now, you’ll need to implement the logic for the hidden field value in your theme’s functions.php file.
}
add_filter(‘fluentform_rendering_form_args’, ‘set_user_profile_check_field_value’, 10, 2);
Replace ‘hidden_field’ with the actual name or ID of your hidden field.
This way, the hidden field value will dynamically change based on whether the user has a profile post or not.