Change name of csv's files

By: Alexa Reigt | Asked: 04/24/2023
ForumsCategory: Code HelpChange name of csv's files
Alexa ReigtAlexa Reigt asked 2 years ago
Hello everybody !  I've 4 forms.
  • Form n°1 and 2 : 2 registers forms for 2 differents roles
  • Form n°3 : 1 form for role 1 after connection
  • Form n°4 : 1 form for role 2 after connection. 
  I tried to change the name of the CSV files received after entry.  For the 2 forms after connection (form n°3 & 4), it works well with this code :  /* Sejour - dispo familles = ID 12 */ add_filter('frm_csv_filename', 'change_csv_filename', 10, 2);
function change_csv_filename($filename, $form){
if ($form->id == 12){//Change 12 to the ID of your form
// Récupération des objets de l'entrée et du formulaire
$entry = FrmEntry::getOne( $form->entry_id );
$form = FrmForm::getOne( $form->id );

// Récupération des valeurs des champs nom, prénom et pseudo
$nom = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 246), $entry->id);
$prenom = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 247), $entry->id);
$pseudo = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 249), $entry->id);

// Remplacement des accents par leur lettre correspondante
$nom = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $nom);
$prenom = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $prenom);
$pseudo = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $pseudo);

// Concaténation des valeurs pour former le nouveau nom de fichier
$new_filename = date("ymdHis", time()) . '_' . sanitize_title_with_dashes($nom . '-' . $prenom . '-' . $pseudo) . '_sejourdispofamilles.csv';//Change the filename here
}
return $new_filename;
}
/* Sejour - inscrire enfants = ID 10 */ add_filter('frm_csv_filename', 'change_csv_filename10', 10, 2);
function change_csv_filename10($filename, $form){
if ($form->id == 10){//Change 10 to the ID of your form
// Récupération des objets de l'entrée et du formulaire
$entry = FrmEntry::getOne( $form->entry_id );
$form = FrmForm::getOne( $form->id );

// Récupération des valeurs des champs organisme et pseudo
$organisme = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 125), $entry->id);
$pseudo = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 250), $entry->id);

// Remplacement des accents par leur lettre correspondante
$organisme = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $organisme);
$pseudo = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $pseudo);

// Concaténation des valeurs pour former le nouveau nom de fichier
$new_filename = date("ymdHis", time()) . '_' . sanitize_title_with_dashes($organisme . '-' . $pseudo) . '_sejourinscrireenfants.csv';//Change the filename here
}
return $new_filename;
}     The problem is, I don't receive any more the CSV files for the 2 forms of registration (form n°1 & 2).  I tried to add the same code to change the csv's name for the 2 forms of registrations with that :  /* Inscription familles = ID 7 */ add_filter('frm_csv_filename', 'change_csv_filename7', 10, 2);
function change_csv_filename7($filename, $form){
if ($form->id == 7){
$entry_id = FrmAppHelper::get_param( 'entry', 0 );
$entry = FrmEntry::getOne( $entry_id );
$nom_field = FrmField::getOne( 242 );
$prenom_field = FrmField::getOne( 243 );
$pseudo_field = FrmField::getOne( 248 );
$nom = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', FrmProEntriesController::get_field_value_shortcode(array('field_id' => $nom_field->id), $entry_id))));
$prenom = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', FrmProEntriesController::get_field_value_shortcode(array('field_id' => $prenom_field->id), $entry_id))));
$pseudo = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', FrmProEntriesController::get_field_value_shortcode(array('field_id' => $pseudo_field->id), $entry_id))));
$nom = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $nom);
$prenom = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $prenom);
$pseudo = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $pseudo);
$filename = date("ymdHis",time()) . '_' . $nom . '_' . $prenom . '_' . $pseudo . '_inscriptionfamille.csv';
}
return $filename;
}   /* Inscription référents = ID 8 */ add_filter('frm_csv_filename', 'change_csv_filename8', 10, 2);
function change_csv_filename8($filename, $form){
if ($form->id == 8){//Change 8 to the ID of your form
// Récupération des objets de l'entrée et du formulaire
$entry = FrmEntry::getOne( $form->entry_id );
$form = FrmForm::getOne( $form->id );

// Récupération des valeurs des champs organisme et pseudo
$organisme = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 118), $entry->id);
$pseudo = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 89), $entry->id);

// Remplacement des accents par leur lettre correspondante
$organisme = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $organisme);
$pseudo = str_replace(array('à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'î', 'ï', 'ô', 'ö', 'ù', 'û', 'ü', 'ÿ'), array('a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'u', 'y'), $pseudo);

// Concaténation des valeurs pour former le nouveau nom de fichier
$new_filename = date("ymdHis", time()) . '_' . sanitize_title_with_dashes($organisme . '-' . $pseudo) . '_inscriptionreferent.csv';//Change the filename here
}
return $new_filename;
}   It doesn't work too.    Do you have an idea if I've wrong code ? And why I didn't receive the CSV's file for forms n°1 & 2 ?    Thanks a lot per advance for your help.    Have a good day ! 

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right