@hube2 thanks for the reply and thanks for the details on how to provide feedback.
What approach would you use to create a multi step form?
I have effectively created tabs which have a next button so the user can scroll through the questions and then the next button changes to the submit button on the last tab. Obviously the validation is the trickiest part as ACF only does validation on submission of the form.
You need to create a function using acf/pre_save_post.
https://www.advancedcustomfields.com/resources/acf-pre_save_post/
I worked out how to do this by adding the following code at the top.
This returns if the page is not the required page:
<?php
if (!is_page('page-slug')) {
return;
}
?>
This doesn’t work for the scenario where you have an ‘add post’ form and an ‘update post’ form. What happens is when you add a new post with the status ‘draft’ it will override that too. I assume the use case for this is a validation workflow i.e. a user adds a post which is set to draft, then somewhere else somebody checks the post to validate it.
@jarvis the page definitely does reload when you submit a front end form and you’re correct you can set the return value, but if I set the return value to the same page it will still reload the page regardless.
I would rather a solution that does not use a plugin.
@hube2 thanks for your reply. The solution was simply to change the settings to ‘Save terms?’ yes 🙂
@hube2 thanks so much that works perfectly! 🙂
@hube2 ok I see, and then in the result do this?:
$_POST['acf']['_post_title'] = $_POST['acf']['field_610b936e9292c'];
I’ll give it a go. Thank you 🙂
@hube2 I see thanks. Any indication as to what that could be? I don’t imagine I’m the only person that has needed to update the title field of more than one post type considering ACF forms does not support core WP fields.
@hube2 none of those. Just if I remove the custom post type condition all together.
@hube2 yes 100%. This is working if I remove the post type conditions and only do it for ‘post’ or for my custom post type alone. But I cannot get it to work with more than one post type.
@hube2 I have added in $post_id and it does not work unfortunately.
@hube2 yes I get Warning: Cannot modify header information – headers already sent by (output started at /wp-includes/formatting.php:5740) /wp-includes/pluggable.php on line 1329
The code on that line is
$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
if ( is_string( $x_redirect_by ) ) {
header( "X-Redirect-By: $x_redirect_by" );
}
header( "Location: $location", true, $status );
return true;
}
endif;
@hube2 sorry I don’t understand how this relates to having more than one custom post type update the post title.
@hube2 there are no plugins I am creating a theme from scratch. I am using Bootstrap though.
I.e.
1- If the acf_form_head(); goes before the get_header, the WYSIWYG format bar doesn’t show
2- If the acf_form_head() goes after the get_header, the format bar works but when I publish a post the page returns a blank
@hube2 the reason it was somehwere else is because I need to have it before the <header> otherwise the form doesn’t work well. However I see the WYSIWYG formatting bar when I move the acf_form_head() next to it. Now the page goes blank when I create the post. So either way I have an issue.
Thank you that was it!
@hube2 when it is a case of updating an existing user I just need to be able to get the id of that user rather than using the wp_insert_user
like I do for creating the user.
@hube2 when I put the user Id directly e.g. 16 it updates the user fine.
I.e.
‘16’
Instead of
‘user_’.$user_id)
@hube2 yes correct and it works for creating a user. But when I try to make a change to a user this function runs and causes an error because the user id already exists. So I suspect it is outputting something other than just user Id which is causing the above string error.
Basically updating the custom post type users results in the error due to line
update_field('field_602ce62b11720', $incident, 'user_'.$user_id)
@hube2 I’ve narrowed it down to the fact that on update/edit, it is expecting a number as opposed to the ‘user_number’ string. If I hard code the id ’60’ and then update that user it works.
Do you know how I can differentiate between user creation and user update so I can pass just the user id for updating and use the ‘user_’. when creating a user?
@hube2 I now have it working with it checking the post type before running the function and it still has this unable to convert to string error when I update the custom post from both WP admin and the frontend. I think the probably is related to the 'user_'.$user_id);
I wonder if somebody can help with something I cannot work out.
I basically have a front end form to create users using ACF fields. I also have a field which I am using ‘Update_field’ for.
This all works for creating the user, however when I update this same custom post I get a critical error, caused by the ‘Update_field’ element specifically.
The critical error is:
Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string in
And here is my code:
function create_user_frontend( $post_id ) {
$first_name = get_field('first_name', $post_id);
$last_name = get_field('last_name', $post_id);
$username = get_field('email', $post_id);
$password = get_field('password', $post_id);
$incident = get_field('related_incident', $post_id, false);
$role = get_field ('role', $post_id);
$userdata= array (
'user_login' => $username,
'user_email' => $username,
'first_name' => $first_name,
'last_name' => $last_name,
'user_pass' => $password,
'role' => $role,
);
$user_id = wp_insert_user($userdata);
update_field('field_602ce62b11720', $incident, 'user_'.$user_id);
}
add_action('acf/save_post', 'create_user_frontend', 20);
Can you not create a variable for review and then just check if it’s set?
<?php
$review= get_field('review');
if (isset ($review)) {
echo '<div class="youtube-player" data-id="' . $String . '"></div>';
} ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.