Support » Plugin: Custom Field Suite » file upload loop doesn’t return empty if no file is uploaded

  • Resolved vanduzled

    (@vanduzled)


    I have a file upload where I input an attachment and it will be echoed as a link on the frontend.

    On the post edit window, when I accidentally press the “+” button to add a loop but without uploading anything, in the output, it will still echo text, but without the source.

    I’ve tried a lot of things but nothing worked:

    if ( $theloop ) :
    

    if ( ! empty ($theloop ) ) :

    if ( $theloop != '' ) :
    

    if ( $theloop ) :

    How can I test if the added loop doesn’t have anything on it?

    here’s my full code:

    <?php $theloop = CFS()->get('file_upload');
    

    if ( ! empty ($theloop ) ) : foreach ( $theloop as $thefile ) {

    		$thesource= $thefile ['upload_file'];?><a>EN</a> ?>
    
    

    <?php}endif;?>

    • This topic was modified 3 years, 8 months ago by vanduzled.
Viewing 1 replies (of 1 total)
  • Plugin Author Matt Gibbs

    (@mgibbs189)

    Your foreach() and empty() may need to be reversed…

    
    foreach ( (array) $theloop as $thefile ) {
        if ( ! empty( $thefile ) ) {
            // do something
        }
    }
    
    • This reply was modified 3 years, 8 months ago by Matt Gibbs.
Viewing 1 replies (of 1 total)
  • The topic ‘file upload loop doesn’t return empty if no file is uploaded’ is closed to new replies.