• Resolved Mina Nielsen

    (@moorlater)


    I’ve been following this snippet: CMB2-Snippet-Library/front-end/cmb2-front-end-submit.php.

    Here’s the problem. Someone writes out their content, leaves the title blank, and submits the form. The page is reloaded with the error message, “New post requires a title”, but their content is gone from the form.

    So I’d like to get their content back from the $_POST data, and set it as the default content when CMB2 builds the form.

    I’ve got the content available in $_POST[‘submitted_post_content’] when the form is shown with the error message.

    How can I tell CMB to use this value for the post content wysiwyg field?

    I’ve been reading the class documentation, and this is the half-assed code I’ve started with, but it’s not working…

    if ( !empty( $_POST['submitted_post_content'] ) ) {
    	$field = $cmb->get_field( 'submitted_post_content' );
    	$field_value = $field->update_data( $_POST['submitted_post_content'], true );
    	var_dump( $field_value ); // returns false :(
    }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Set the default value of a field in a front-end form’ is closed to new replies.