Hey there,
So I am using gform_pre_submission to create a csv out of the pre_entry data. That all is working fine. HOWEVER, when I then try to save the new link I’ve created to an uploadfile input, it wont save?
$_POST['input_74'] = $file_url;
I even try it with some JavaScript:
?><script>
document.querySelector("input#input_2_74").value = <?php echo $file_url ?>
</script>
<?php
So what gives? Here is the full code:
add_action( 'gform_pre_submission_2', 'gaws_pre_submission_handler' );
function gaws_pre_submission_handler( $form ) {
$form_id = $form['id'];
if( $form_id == 2 ){
$upload_dir = wp_upload_dir();
$data = array();
$csv = array(
array(
'Client ID',
'Requestor Name (First Last)',
'Requestor Email Address',
'Administrator Name (First Last)',
'Administrator Email Address',
'Survey Project',
'Client Organization',
'Client Cohort',
'Participant Name (First)',
'Participant Name (Last)',
'Participant Email Address',
'Division',
'Department',
'Level',
'Team',
'Location',
'Rater Name (First)',
'Rater Name (Last)',
'Rater Email Address',
'Rater Group'
)
);
$find[] = ',';
$input_44 = str_replace( $find, ',', rgpost( 'input_44' ) ); //Client ID
$input_4 = str_replace( $find, ',', rgpost( 'input_4' ) ); // Name (first last)/Requestor Name (First Last)
$input_5 = str_replace( $find, ',', rgpost( 'input_5' ) ); // Email Address/Requestor Email Address
$input_7 = str_replace( $find, ',', rgpost( 'input_7' ) ); // Name (first last)/Administrator Name (First Last)
$input_8 = str_replace( $find, ',', rgpost( 'input_8' ) ); // Email Address/Administrator Email Address
$input_12 = str_replace( $find, ',', rgpost( 'input_12' ) ); // Survey Project
$input_13 = str_replace( $find, ',', rgpost( 'input_13' ) ); // Client Organization
$input_14 = str_replace( $find, ',', rgpost( 'input_14' ) ); // Client Cohort
$input_21 = str_replace( $find, ',', rgpost( 'input_21' ) ); // First Name/Participant Name (First)
$input_22 = str_replace( $find, ',', rgpost( 'input_22' ) ); // Last Name/Participant Name (Last)
$input_23 = str_replace( $find, ',', rgpost( 'input_23' ) ); // Email Address/Participant Email Address
$input_25 = str_replace( $find, ',', rgpost( 'input_25' ) ); // Division
$input_26 = str_replace( $find, ',', rgpost( 'input_26' ) ); // Department
$input_27 = str_replace( $find, ',', rgpost( 'input_27' ) ); // Level
$input_28 = str_replace( $find, ',', rgpost( 'input_28' ) ); // Team
$input_71 = str_replace( $find, ',', rgpost( 'input_71' ) ); // Location
$input_30 = str_replace( $find, ',', rgpost( 'input_30' ) );
array_push($csv, array($input_44, $input_4, $input_5, $input_7, $input_8, $input_12, $input_13, $input_14, $input_21, $input_22, $input_23, $input_25, $input_26, $input_27, $input_28, $input_71, $input_30[0], $input_30[1], $input_30[2], $input_30[3]) );
//}
$str = wp_generate_password( 6, false, false);
$dir = 'wp-content/uploads/csv';
if( ! is_dir ( $dir ) ){
mkdir($dir);
}
$file_url = $dir . '/entry_'.$str.'.csv';
$csv_handler = fopen ($file_url,'w');
foreach ($csv as $fields) {
fputcsv($csv_handler, $fields);
}
fclose ($csv_handler);
$_POST['input_74'] = $file_url;
?><script>
document.querySelector("input#input_2_74").value = <?php echo $file_url ?>
</script>
<?php
}
}