• I used below code for upload file from front end but when I update the form it disappear and not shown on the screen where I am displaying it. Can you help me? I would be very thankful for your valuable time.

    “array(
    ‘name’ => __(‘Upload Files’, ‘wp-job-board-pro’),
    ‘id’ => $prefix . ‘upload_files’,
    ‘type’ => ‘file’,
    ‘options’ => array(
    ‘add_upload_file_text’ => __(‘Add or upload files’, ‘wp-job-board-pro’),
    ‘file_list’ => true, // Enable multiple file uploads
    ‘query_args’ => array(
    ‘type’ => array(‘image/jpeg’, ‘image/png’, ‘application/pdf’, ‘application/msword’, ‘application/vnd.openxmlformats-officedocument.wordprocessingml.document’), // Specify allowed file types
    ‘size’ => 5242880, // Set maximum file size (5 MB in bytes)
    ‘preview_size’ => ‘thumbnail’,
    ),
    ),
    )”

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    A link to where we can see the form would be helpful, at least as long as it’s not behind the need to log in. Beyond that, not sure what would be causing the field to not show after submission, as that could be part of anything, including your active theme.

    Thread Starter bilalgmughal760

    (@bilalgmughal760)

    I am very thankful for giving me your valuable time!

    I am sharing my issue with more clearly in the video : https://www.youtube.com/watch?v=GnT4CNNsGyU

    Main issue : When end user upload file and update the form it disappear from the form that’s why it not shown in the Profile page (where i am fetching filled data.).

    I used this code for taking data from the front end user :

    array(

                            ‘name’              => __( ‘Image’, ‘wp-job-board-pro’ ),

                            ‘id’                => ‘upload_fles’,

                            ‘type’              => ‘file’,

                            ‘ajax’              => true,

                            ‘multiple_files’    => false,

                            ‘mime_types’        => array( ‘gif’, ‘jpeg’, ‘jpg’, ‘jpg|jpeg|jpe’, ‘png’ ),

                        ),

    "
    /////////////////////////////////////////////////
    and this is my code for displaying it on the front end :
    " <div>                 <?php                 if (!empty($item['upload_fles'])) {                     echo '<p>Uploaded Files:</p>';                     echo '<ul>';                     foreach ($item['upload_files'] as $file) {                         echo '<li><a href="' . esc_url($file['url']) . '">' . esc_html($file['title']) . '</a></li>';                     }                     echo '</ul>';                 }                 ?>                 <p>my files</p>                 </div> "

    [ Login details deleted, never post that on the Internet please. Ever. ]

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @bilalgmughal760 Do not ask anyone to log into your site. Not a testing site, not a staging site and never a production site. It is not safe and volunteers on this site are forbidden to accept that access.

    I’ve removed that part. Please work with the support person to solve your problem here.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    @bilalgmughal760 have you done any checks to see if the data and information is being saved to the database/media library? Just in case this is a fetching/display issue as opposed to a data saving issue?

    Thread Starter bilalgmughal760

    (@bilalgmughal760)

    Yes! I have done different checks too. my code :

     if (!empty($item['uploaded_files'])) {
          echo '<p>Uploaded Files:</p>';
          echo '<ul>';
          foreach ($item['uploaded_files'] as $file) {
             echo '<li><a href="' . esc_url($file['url']) . '">' . esc_html($file['title']) . '</a></li>';
          }
          echo '</ul>';
      }

    ?I see my files are not saved in my media folder or anywhere in the database.
    I use group fields and all other types of fields like text, textarea, etc are working fine and handling easily except for this “file” type. Is there anything that I am missing to store that file on save that file or probably missing to step to handle the save option?

    Thread Starter bilalgmughal760

    (@bilalgmughal760)

    Can I use the file type field while creating a group of fields using the CMB2 plugin? If I can use then tell me what should be code for it I used this code for defining field :

    array(
                            'name' => __( 'upload flag', 'wp-job-board-pro' ),
                            'id' => 'seaman', // Ensure it's a unique ID
                            'type' => 'file',
                            'options' => array(
                                'url' => false, // Do not display the text field for the file URL
                            ),
                            'text' => array(
                                'add_upload_file_text' => 'Add File', // Button text for adding/uploading files
                            ),
                            'query_args' => array(
                                'type' => 'image', // Restrict to image files
                            ),
                            'preview_size' => 'small', // Set the size of the preview image
                            'save_id' => true, // Save the file ID in the database
                        ),

    for displaying file to the front end I use this code :

    if (!empty($item['seaman_id'])) {
                        echo '<p>Uploaded Files:</p>';
                        echo '<ul>';
                        foreach ($item['seaman_id'] as $file) {
                            if ($file['error']) {
                                // Handle the upload error
                                echo '<li>File upload error: ' . esc_html($file['error']) . '</li>';
                            } else {
                                // File was uploaded successfully
                                echo '<li><a href="' . esc_url($file['url']) . '">' . esc_html($file['title']) . '</a></li>';
                            }
                        }
                        echo '</ul>';
                    }

    I used checks while fetching the file like as echo ‘<p>Uploaded Files:</p>’;
    but I can see it not enter into if condition.

    When I upload file and trying to update the form uploaded file disappear and not saved into database but all other fields are store and fetching properly in the same group of fields with same submitting form.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m not going to be able to effectively troubleshoot things overall given that there hasn’t been a complete snippet thus far for all the CMB2 config (something we haven’t asked for thus far, so on us technically), but also because it feels like this is all meant to be part of a membership/community type site which makes it difficult to set up in a matching environment.

    That said, perhaps try to reduce things down to just the bare bones parts that are failing, and build up from there, to see if it gets resolved. For example, reduce the form in question to JUST the file field, and for the arguments for the file field, use only the required config parts and see if it works at that time. Then start adding in the parts that are a bit more specific like query_args and preview_size etc.

    Also, I know CMB2 has https://github.com/CMB2/CMB2-Snippet-Library/ which is a bunch of snippets for various functionality, I would be surprised if there were no snippets that had file based uploading as potential examples to start with and build up from.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Issue with CMB2 plugin field type “file”’ is closed to new replies.