Hi guys. Was hoping for a bit of help on this. I currently have a function in my functions.php file the allows the addition of shortcode on Contact Form 7, like so:
wpcf7_add_shortcode('wpcf7_doclink', 'add_doclink', true);
function add_doclink() {
if($the_file_url){
$html = '<input type="hidden" name="your-doclink" value="'.$the_file_url.'">';
}
else{
$html = null;
}
return $html;
}
In my template file I have the a flexible content loop which I would like to use a sub field from in the above function:
<?php if( have_rows('level') ): ?>
...
<?php while ( have_rows('level') ) : the_row(); ?>
<?php if( get_row_layout() == 'download_form' ): ?>
...
<?php $the_file_url = get_sub_field('document_file')?>
...
<?php endif; ?>
...
<?php endwhile; ?>
<?php endif;?>
The problem seems to be the scope of the variables. I can’t get the variable $the_file_url into the function. Can anyone help with this? The function works if it isn’t in a flexible loop.