Support Forum » User Profile

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: Unable to save due to email field is set to required #49315
    OmarOmar
    Participant

    Can confirm, this is not fixed yet.. Meta Box AIO Version 3.3.1

    OmarOmar
    Participant

    Hello Peter, thanks for the feedback, i will!
    All the best Omar

    OmarOmar
    Participant

    How can I successfully integrate the data from a BricksBuilder front-end form into a CPT created with Meta Box, ensuring image uploads work seamlessly without requiring user registration for submissions?

    Code i use currently to get other fields data and creating the post:

    
    function add_story( $form ) {
        $fields = $form->get_fields();
        $name = $fields['form-field-1'];
        $email = $fields['form-field-2'];
        $story = $fields['form-field-3'];
    	
    	$new_post['post_type'] = 'story';
    	$new_post['post_status'] = 'draft';
    	$new_post['post_title'] = $name;
    	$new_post['post_content'] = $story;
    	
    	$new_post['meta_input']['email'] = $email;
    
    	$post_id = wp_insert_post( $new_post );
    	
    }
    
    add_action( 'bricks/form/custom_action', 'add_story', 10, 1 );
    

    I have tried to extend the code but without success, also tried using the option to save the images localy first with the form-option also without any success.

    
    function add_story( $form ) {
        $fields = $form->get_fields();
        $name = $fields['form-field-1'];
        $email = $fields['form-field-2'];
        $story = $fields['form-field-3'];
        $uploaded_images = $form->get_uploaded_files();
    
        $new_post = array(
            'post_type' => 'story',
            'post_status' => 'publish',
            'post_title' => $name,
            'post_content' => $story,
            'meta_input' => array(
                'email' => $email,
            ),
        );
    
        $post_id = wp_insert_post( $new_post );
    
        foreach ( $uploaded_images['form-field-4'] as $image ) {
            $image_url = $image['url'];
            $image_name = basename( $image_url );
            $image_path = WP_CONTENT_DIR . '/uploads/' . $image_name;
    
            $image_data = file_get_contents( $image_url );
            if ( $image_data !== false ) {
                file_put_contents( $image_path, $image_data );
    
                $image_attachment = array(
                    'post_mime_type' => $image['type'],
                    'post_title' => sanitize_file_name( $image_name ),
                    'post_content' => '',
                    'post_status' => 'inherit',
                    'post_parent' => $post_id,
                );
    
                $attach_id = wp_insert_attachment( $image_attachment, $image_path, $post_id );
                if ( ! is_wp_error( $attach_id ) ) {
                    require_once( ABSPATH . 'wp-admin/includes/image.php' );
                    $attach_data = wp_generate_attachment_metadata( $attach_id, $image_path );
                    wp_update_attachment_metadata( $attach_id, $attach_data );
    
                    set_post_thumbnail( $post_id, $attach_id );
                } else {
                    error_log( 'Error inserting: ' . $attach_id->get_error_message() );
                }
            } else {
                error_log( 'Error downloading: ' . $image_url );
            }
        }
    }
    
    add_action( 'bricks/form/custom_action', 'add_story', 10, 1 );
    

    Sorry didnt put the divs!

Viewing 3 posts - 1 through 3 (of 3 total)