discord.js declaration or statement expected problem - discord.js

What is wrong with this code? All the else get the problem "declaration or statement expected'. Please help me, I am new in discord.js. I needed to take all the links away to post this here.
switch(args[0]){
case 'gymlista':
const embed0 = new Discord.RichEmbed()
embed0.setTitle('Gymlista')
embed0.setColor('#0099ff')
embed0.setURL('')
embed0.setAuthor('POGO Huddinge', '')
embed0.setDescription('En karta samt lista över alla gym i Huddinges chattar. Klicka på länken ovan!')
embed0.setThumbnail('')
embed0.setTimestamp('')
embed0.setFooter('!hjälp för en lista över fler commands.', '');
msg.channel.send(embed0);
break;
case 'hjälp':
const embedh = new Discord.RichEmbed()
embedh.setTitle('Allmänt')
embedh.setColor('#0099ff')
embedh.setAuthor('POGO Huddinge', '')
embedh.setDescription('POGO HUDDINGE BOT är skapad och programmerad av #Pushos och är avsedd till Pokémon Go Huddinges discord server. Kontakta gärna mig om du har några frågor eller funderingar. :blush:')
embedh.setThumbnail('')
embedh.setTimestamp('')
embedh.setFooter('!hjälp för en lista över fler commands.', '');
embedh.addField('Version', 'v. 1.0 5');
embedh.addField('Datum skapad', '26/12 -2019')
embedh.addField('Skapad av', '#Pushos')
embedh.addField('Prefix', '!')
embedh.addField('Fungerar i (kanal)', '#botcommands')
msg.channel.send(embedh);
const embedh2 = new Discord.RichEmbed()
embedh2.setTitle('Commands')
embedh2.setColor('#0099ff')
embedh2.setAuthor('POGO Huddinge', '')
embedh2.setDescription('Nedan kommer en lista över alla commands som går att använda med denna bot. Alla commands skrivs i kanalen #botcommands med ett ! innan kommandot.')
embedh2.setThumbnail('')
embedh2.setTimestamp('')
embedh2.setFooter('!hjälp för en lista över alla commands, samt information.', '');
embedh2.addField('!hittagym <gymnamn>', 'Tar upp vägbeskrivning över gymmet du letar efter.');
embedh2.addField('!gymlista', 'Karta samt lista över alla gym i Huddinges chattar.')
msg.channel.send(embedh2);
break;
case 'hittagym':
if(args[1] === 'Asmunds'){
if(args[2] === 'häst'){
const embed = new Discord.RichEmbed()
embed.setTitle('Asmunds häst')
embed.setColor('#0099ff')
embed.setURL('')
embed.setAuthor('POGO Huddinge', '')
embed.setDescription('**EX Raid Gym**')
embed.setThumbnail('')
embed.setTimestamp('')
embed.setFooter('!hjälp för en lista över fler commands.', '');
embed.addField('Nära:', 'Fullersta gårdsväg 18');
embed.addField('Koordinater:', '59.23911, 17.97408')
embed.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed);
}}else{
if(args[1] === 'Sjödalsparkens'){
if(args[2] === 'Utomhusscen'){
const embed2 = new Discord.RichEmbed()
embed2.setTitle('Sjödalsparkens Utomhusscen')
embed2.setColor('#0099ff')
embed2.setURL('')
embed2.setAuthor('POGO Huddinge', '')
embed2.setDescription('**Ex Raid Gym**')
embed2.setThumbnail('')
embed2.setTimestamp('')
embed2.setFooter('!hjälp för en lista över fler commands.', '');
embed2.addField('Nära:', 'Klockarvägen 2');
embed2.addField('Koordinater:', '59.23698, 17.98447')
embed2.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed2);
}}else{
if(args[1] === 'Rådsparkens'){
if(args[2] === 'Utegym'){
const embed3 = new Discord.RichEmbed()
embed3.setTitle('Rådsparkens Utegym')
embed3.setColor('#0099ff')
embed3.setURL('')
embed3.setAuthor('POGO Huddinge', '')
embed3.setDescription('**Ex Raid Gym**')
embed3.setThumbnail('')
embed3.setTimestamp('')
embed3.setFooter('!hjälp för en lista över fler commands.', '');
embed3.addField('Nära:', 'Kommunalvägen 27A');
embed3.addField('Koordinater:', '59.23994, 17.98693')
embed3.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed3);
}}else{
if(args[1] === 'Fullersta'){
if(args[2] === 'Bio'){
const embed4 = new Discord.RichEmbed()
embed4.setTitle('Fullersta Bio')
embed4.setColor('#0099ff')
embed4.setURL('')
embed4.setAuthor('POGO Huddinge', '')
')
embed4.setTimestamp('')
embed4.setFooter('!hjälp för en lista över fler commands.', '');
embed4.addField('Nära:', 'Norrängsvägen 1');
embed4.addField('Koordinater:', '59.24016, 17.97292')
embed4.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed4);
}}else{
if(args[1] === 'Elhus'){
const embed5 = new Discord.RichEmbed()
embed5.setTitle('Elhus')
embed5.setColor('#0099ff')
embed5.setURL('')
embed5.setAuthor('POGO Huddinge', '')
embed5.setThumbnail('')
embed5.setTimestamp('')
embed5.setFooter('!hjälp för en lista över fler commands.', '');
embed5.addField('Nära:', 'Mossvägen 3');
embed5.addField('Koordinater:', '59.23909, 17.97096')
embed5.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed5);
}}else{
if(args[1] === 'Rådjur'){
const embed6 = new Discord.RichEmbed()
embed6.setTitle('Rådjur')
embed6.setColor('#0099ff')
embed6.setURL('')
embed6.setAuthor('POGO Huddinge', '')
embed6.setThumbnail('')
embed6.setTimestamp('')
embed6.setFooter('!hjälp för en lista över fler commands.', '');
embed6.addField('Nära:', 'Britas gränd 8');
embed6.addField('Koordinater:', '59.23779, 17.97002')
embed6.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed6);
}}else{
if(args[1] === 'Växthus1'){
const embed7 = new Discord.RichEmbed()
embed7.setTitle('Växthus1')
embed7.setColor('#0099ff')
embed7.setURL('')
embed7.setAuthor('POGO Huddinge', '')
')
embed7.setTimestamp('')
embed7.setFooter('!hjälp för en lista över fler commands.', '');
embed7.addField('Nära:', 'Patron Pehrs väg 5');
embed7.addField('Koordinater:', '59.23631, 17.9767')
embed7.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed7);
}}else{
if(args[1] === 'Snäckan'){
const embed8 = new Discord.RichEmbed()
embed8.setTitle('Snäckan')
embed8.setColor('#0099ff')
embed8.setURL('')
embed8.setAuthor('POGO Huddinge', '')
embed8.setThumbnail('')
embed8.setTimestamp('')
embed8.setFooter('!hjälp för en lista över fler commands.', '');
embed8.addField('Nära:', 'Huddinge Stationsplan 2');
embed8.addField('Koordinater:', '59.23691, 17.97956')
embed8.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed8);
}}else{
if(args[1] === 'Sälfontänen'){
const embed9 = new Discord.RichEmbed()
embed9.setTitle('Sälfontänen')
embed9.setColor('#0099ff')
embed9.setURL('')
embed9.setAuthor('POGO Huddinge', '')
embed9.setThumbnail('')
embed9.setTimestamp('')
embed9.setFooter('!hjälp för en lista över fler commands.', '');
embed9.addField('Nära:', 'Sjödalstorget 9');
embed9.addField('Koordinater:', '59.23615, 17.98252')
embed9.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed9);
}}else{
if(args[1] === 'Mimi'){
const embed10 = new Discord.RichEmbed()
embed10.setTitle('Mimi')
embed10.setColor('#0099ff')
embed10.setURL(')
embed10.setAuthor('POGO Huddinge', '')
embed10.setThumbnail('')
embed10.setTimestamp('')
embed10.setFooter('!hjälp för en lista över fler commands.', '');
embed10.addField('Nära:', 'Sjödalsvägen 16');
embed10.addField('Koordinater:', '59.23475, 17.98312')
embed10.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed10);
}}else{
if(args[1] === 'Stenfontän'){
const embed1 = new Discord.RichEmbed()
embed1.setTitle('Stenfontän')
embed1.setColor('#0099ff')
embed1.setURL('')
embed1.setAuthor('POGO Huddinge', '')
embed1.setThumbnail('')
embed1.setTimestamp('')
embed1.setFooter('!hjälp för en lista över fler commands.', '');
embed1.addField('Nära:', 'Gymnasietorget 5');
embed1.addField('Koordinater:', '59.24311, 17.99626')
embed1.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed1);
}}else{
if(args[1] === 'Stenfontän3'){
}}else{
if(args[1] === 'Stenfontän4'){
}}}}
break;
case 'clear':
if(!args[1]) return msg.reply('Error please define second arg')
msg.channel.bulkDelete(args[1]);
break;
}
})

Show pls your import block
And you have SyntaxError at setAuthor block in this partt of code
if(args[1] === 'Fullersta'){
if(args[2] === 'Bio'){
const embed4 = new Discord.RichEmbed()
embed4.setTitle('Fullersta Bio')
embed4.setColor('#0099ff')
embed4.setURL('')
embed4.setAuthor('POGO Huddinge', '')
')
embed4.setTimestamp('')
embed4.setFooter('!hjälp för en lista över fler commands.', '');
embed4.addField('Nära:', 'Norrängsvägen 1');
embed4.addField('Koordinater:', '59.24016, 17.97292')
embed4.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed4);
And this
const embed7 = new Discord.RichEmbed()
embed7.setTitle('Växthus1')
embed7.setColor('#0099ff')
embed7.setURL('')
embed7.setAuthor('POGO Huddinge', '')
')
embed7.setTimestamp('')
embed7.setFooter('!hjälp för en lista över fler commands.', '');
embed7.addField('Nära:', 'Patron Pehrs väg 5');
embed7.addField('Koordinater:', '59.23631, 17.9767')
embed7.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed7);

Related

"Cannot read property 'cache' of undefined" when I check a member role

I want to make a mute command for my Discord bot but that create errors:
C:\Program Files\nodejs\node.exe .\index.js
|------ Bot on ------|
index.js:22
Uncaught TypeError: Cannot read property 'cache' of undefined
No debugger available, can not send 'variables'
Process exited with code 1
I want to check if the user who is mentionned has already the mute role and if the executor has an admin role. But that create this error.
My code:
bot.on("message", async message => {
if(message.content.startsWith(prefix + "mute")){
let User = message.mentions.users.first();
let time = message.content.split(" ").slice(2)
let reason = message.content.split(" ").slice(3)
if(!reason){ let reason = "aucune"}
if(!time || !User) return message.reply("Veuillez entrer une commande valide !\n" + prefix + "mute #user <temps> <raison>")
let dUser = User.id
if(dUser == message.author.id) return message.reply("Vous ne pouvez pas vous mute vous même !")
if(isNaN(time[0]) || time < 1) return message.reply("Veuillez entrer une valeur chiffrée et supérieur à 1 !")
let muterole = "793840735266013205"
che
if(User.roles.cache.has(muterole)) return message.reply("Ce membre est déjà mute !")
if(!message.author.roles.cache.has("783758067111428126" || "783758066138218577")) return message.reply("Vous n'avez pas la permission d'utiliser cette commande !")
if(User.roles.cache.has("783758067111428126" || "783758066138218577")) return message.reply("Vous ne pouvez pas mute un membre du staff !")
let emb = new Discord.MessageEmbed()
.setTitle(Mute)
.setDescription(User.username + " a bien été mute par " + message.author.username + " pendant " + time[0] + " secondes pour la raison suivante : " + reason)
.setColor("#E74C3C")
pendant " + time[0] + " secondes pour la raison suivante : " + reason)
User.roles.add(muterole)
setTimeout(() => {
User.roles.remove(muterole)
let reply = new Discord.MessageEmbed()
.setDescription(User + " a bien été unmute !")
.setColor("#E74C3C")
message.guild.channels.cache.get("795063422386569298").send(reply)
let mp = new Discord.MessageEmbed()
.setDescription("Vous avez été unmute de " + guild)
.setColor("#E74C3C")
message.author.send(mp)
}, time[0] = 60000
)}
})
Don’t worry about French words.
Your code is not going to do what you want it to do, because you messed up some parts. User will be the first mentioned user that can be found in your arguments. So if you mention the user right at the first position of your arguments, it will be at index 0. That is because the arguments get stored in an array and arrays always starts at index 0. That means now your following arguments have to be at index 1 and 2. So you can change your time and reason into:
let time = message.content.split(" ").slice(1);
let reason = message.content.split(" ").slice(2).join(" ");
Make sure you use .join(" ") at your reason, that will allow you to add multiple words for the reason. The next mistake is in the if-statement where you ask if there is no reason. You create a new variable inside the statement, which makes no sense. You just have to do:
if(!reason){ reason = "aucune"; }
Now if there is no reason provided the reason will be aucune.
If you want to ask if a user has the mute role already, you can use a GuildMember Object. That would look like this:
if(message.guild.member(User).roles.cache.has(muterole)) return message.reply("Ce membre est déjà mute !")
After that if-statement you ask if a user has certain roles and if he don't has this roles, he has no permission. Something like that should always be the first line of code of such a command and it should look like this:
if(!message.author.roles.cache.has("783758067111428126") || !message.author.roles.cache.has("783758066138218577")) return message.reply("Vous n'avez pas la permission d'utiliser cette commande !")
The same procedure with the following if-statement:
if(User.roles.cache.has("783758067111428126") || User.roles.cache.has("783758066138218577")) return message.reply("Vous ne pouvez pas mute un membre du staff !")
Then in your embed you are using time[0], although time is not an array. It just has to be time.
Your code should look like this now:
bot.on("message", async message => {
if(message.content.startsWith(prefix + "mute")){
if(!message.author.roles.cache.has("783758067111428126") || !message.author.roles.cache.has("783758066138218577")) return message.reply("Vous n'avez pas la permission d'utiliser cette commande !")
let User = message.mentions.users.first();
if(User.roles.cache.has("783758067111428126") || User.roles.cache.has("783758066138218577")) return message.reply("Vous ne pouvez pas mute un membre du staff !")
let time = message.content.split(" ").slice(2)
let reason = message.content.split(" ").slice(3)
if(!reason){ reason = "aucune"; }
if(!time || !User) return message.reply("Veuillez entrer une commande valide !\n" + prefix + "mute #user <temps> <raison>")
let dUser = User.id
if(dUser == message.author.id) return message.reply("Vous ne pouvez pas vous mute vous même !")
if(isNaN(time) || time < 1) return message.reply("Veuillez entrer une valeur chiffrée et supérieur à 1 !")
let muterole = "793840735266013205"
if(message.guild.member(User).roles.cache.has(muterole)) return message.reply("Ce membre est déjà mute !")
let emb = new Discord.MessageEmbed()
.setTitle(Mute)
.setDescription(User.username + " a bien été mute par " + message.author.username + " pendant " + time + " secondes pour la raison suivante : " + reason)
.setColor("#E74C3C")
User.roles.add(muterole)
setTimeout(() => {
User.roles.remove(muterole)
let reply = new Discord.MessageEmbed()
.setDescription(User + " a bien été unmute !")
.setColor("#E74C3C")
message.guild.channels.cache.get("795063422386569298").send(reply)
let mp = new Discord.MessageEmbed()
.setDescription("Vous avez été unmute de " + message.guild)
.setColor("#E74C3C")
message.author.send(mp)
}, time
)}
})

How can I attach a file to a message?

I want my bot to forward a file to the mentioned user when using the command, the problem is that I don't know how to do it.
if (command === "file") {
if (message.channel.id != "700038969253167125") return;
message.delete();
message.channel.send(`> <#${message.author.id}> ✅`)
let filejoin = args.join(" ");
if (!filejoin)
client.channels.cache.get('700052786909282344').send(`:information_source: **|** Ha llegado un nuevo archivo (<#${message.author.id}>)\n\n"${filejoin}"`);
if (message.author.bot) return;
client.channels.cache.get('700052786909282344').send(`:information_source: **|** Ha llegado un nuevo archivo (<#${message.author.id}>)\n\n"${filejoin}"`).then(async m => {
});
}
You can send files using the .send() method.
As you stated in the comments of this answer, you want the file attached to the message containing the command to be sent to you. You can do that like so:
const user = client.users.cache.get("YOUR_ID")
if (message.attachments.array().length) {
message.attachments.forEach((attachment) => user.send({ files: [ attachment ] }))
user.send(`These files were sent by ${message.author.tag}`)
}

Datatables change interface language

I am currently using angular-datatables.
How can I see the interface of the table in other languages?
I mean the "Show entries", "Search:", "Showing 1 to 10 of 20 entries" literals fore example in Spanish.
You need to define a language struct like this (danish implementation, what I am using in my angular-datatables apps) :
var language = {
"sEmptyTable": "Ingen tilgængelige data (prøv en anden søgning)",
"sInfo": "Viser _START_ til _END_ af _TOTAL_ rækker",
"sInfoEmpty": "Viser 0 til 0 af 0 rækker",
"sInfoFiltered": "(filtreret ud af _MAX_ rækker ialt)",
"sInfoPostFix": "",
"sInfoThousands": ",",
"sLengthMenu": "Vis _MENU_ rækker",
"sLoadingRecords": "Henter data...",
"sProcessing": "Processing...",
"sSearch": "Filter:",
"sZeroRecords": "Ingen rækker matchede filter",
"oPaginate": {
"sFirst": "Første",
"sLast": "Sidste",
"sNext": "Næste",
"sPrevious": "Forrige"
},
"oAria": {
"sSortAscending": ": activate to sort column ascending",
"sSortDescending": ": activate to sort column descending"
}
}
There is a bunch of languages here -> https://www.datatables.net/plug-ins/i18n/
And then you include the language using the withLanguage() option method
.withLanguage(language)
demo -> http://plnkr.co/edit/RCrqM3z7qwsUfFwy8HE6?p=preview
I created a .ts file like this:
export class LanguageApp {
public static spanish_datatables = {
processing: "Procesando...",
search: "Buscar:",
lengthMenu: "Mostrar _MENU_ &elementos",
info: "Mostrando desde _START_ al _END_ de _TOTAL_ elementos",
infoEmpty: "Mostrando ningún elemento.",
infoFiltered: "(filtrado _MAX_ elementos total)",
infoPostFix: "",
loadingRecords: "Cargando registros...",
zeroRecords: "No se encontraron registros",
emptyTable: "No hay datos disponibles en la tabla",
paginate: {
first: "Primero",
previous: "Anterior",
next: "Siguiente",
last: "Último"
},
aria: {
sortAscending: ": Activar para ordenar la tabla en orden ascendente",
sortDescending: ": Activar para ordenar la tabla en orden descendente"
}
}
}
Then in the component that was loading the DataTable just put that config inside dtOptions:
this.dtOptions = {
language: LanguageApp.spanish_datatables
};
In Angular2+ what worked for me is quite the same as mentioned by #davidkonrad, but without the starting letters (s and o), and adding the language as an attribute of the dtOptions. I.e.:
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 10,
dom: 'Bfrtip',
buttons: [
/*'print',
'csv'*/
],
responsive: true,
/* below is the relevant part, e.g. translated to spanish */
language: {
processing: "Procesando...",
search: "Buscar:",
lengthMenu: "Mostrar _MENU_ éléments",
info: "Mostrando desde _START_ al _END_ de _TOTAL_ elementos",
infoEmpty: "Mostrando ningún elemento.",
infoFiltered: "(filtrado _MAX_ elementos total)",
infoPostFix: "",
loadingRecords: "Cargando registros...",
zeroRecords: "No se encontraron registros",
emptyTable: "No hay datos disponibles en la tabla",
paginate: {
first: "Primero",
previous: "Anterior",
next: "Siguiente",
last: "Último"
},
aria: {
sortAscending: ": Activar para ordenar la tabla en orden ascendente",
sortDescending: ": Activar para ordenar la tabla en orden descendente"
}
}
};

What is wrong when I call this array from a variable?

I have been do it a template page for Wordpress Theme. In it, have to filter some tags from an user field.
But for test, I do it that:
$user_id = get_current_user_id();
$contexto = get_user_meta($user_id, 'contexto', true);
$contexto = '"' . $contexto . '"';
$array = array (
"Buscando mi nicho​" => "buscando-mi-nicho",
"Montando mi blog" => "montando-mi-plataforma",
"Buscando lectores" => "buscando-lectores",
"Construyendo mi lista de correo​" => "construyendo-mi-lista-de-correo",
"Vendiendo mi primer producto/servicio​" => "vendiendo-mi-primer-productoservicio",
"Buscando más clientes​​​" => "escalar-ventas",
"A punto de dar el gran salto (para vivir de mi blog)​" => "a-punto-de-dar-el-gran-salto-para-vivir-de-mi-blog",
"Ya soy Knowmada Full Time​" => "ya-soy-knowmada-full-time"
);
$etiqueta = $array[$contexto];
$user_first = get_user_meta( $user_id, 'first_name', true );
echo '<p>Hola '. $user_first . '. Queremos ayudarte a progresar, y tu etapa actual es <strong>' . $contexto . '</strong>, por eso, te recomendamos los siguientes contenidos con la etiqueta <b>' . $etiqueta . '</b></p>';
And I get:
Hola Javier. Queremos ayudarte a progresar, y tu etapa actual es "Montando mi blog", por eso, te recomendamos los siguientes contenidos con la etiqueta
You can see, that I don't get the variable $etiqueta.
If I put, for example:
$etiqueta = $array["Montando mi blog"];
I get:
Hola Javier. Queremos ayudarte a progresar, y tu etapa actual es "Montando mi blog", por eso, te recomendamos los siguientes contenidos con la etiqueta montando-mi-plataforma
So I get $etiqueta.
What is wrong whit:
$etiqueta = $array[$contexto];
It is because the keys in your array to not have the double quotes ("). Remove the line:
$contexto = '"' . $contexto . '"';
and it should work.

Cakephp Data validation - This field cannot be left blank

I'm using cakephp and I get a strange behavior with it.
Here is my validation rule in the Model:
public $validate = array(
'flyer' => array(
'rule' => array('fileValidation', 'flyer', array('image/jpeg', 'image/pjpeg'), NULL, TRUE)
)
// Other rules...
);
Here is the fileValidation method (yes I'm french =) )
public function fileValidation(array $check, $field, array $allowedMimeTypes = NULL, $maxFileSize = NULL, $allowEmpty = FALSE)
{
$file = array_shift($check);
$message = NULL;
if($file['error'] === UPLOAD_ERR_OK){
// checking uploaded file
if(empty($file['tmp_name']) || empty($file['tmp_name']) || $file['tmp_name'] === 'none' || !is_uploaded_file($file['tmp_name'])){
$message = "Une erreur est survenue lors de l'envoi du fichier, veuillez réessayer à nouveau. Si le problème persiste, merci de contacter le support technique.";
}
// checking mimeTypes if required
elseif(!empty($allowedMimeTypes) && !in_array($file['type'], $allowedMimeTypes)){
$message = "Le type de fichier envoyé n'est pas celui attendu.";
}
// checking file size if required
elseif(!empty($maxFileSize) && $file['size'] > $maxFileSize){
$message = "Le fichier envoyé est trop volumineux, réduisez sa taille et réessayez.";
}
else{
return TRUE;
}
}
elseif($file['error'] === UPLOAD_ERR_NO_FILE){
// validates if no upload is allowed
if(!$allowEmpty){
$message = "Une erreur est survenue lors de l'envoi du fichier, veuillez réessayer à nouveau. Si le problème persiste, merci de contacter le support technique.";
}
else{
return TRUE;
}
}
elseif($file['error'] === UPLOAD_ERR_INI_SIZE){
$message = "Le fichier envoyé est trop volumineux, réduisez sa taille et réessayez.";
}
elseif($file['error'] === UPLOAD_ERR_FORM_SIZE){
$message = "Le fichier envoyé est trop volumineux, réduisez sa taille et réessayez.";
}
elseif($file['error'] === UPLOAD_ERR_PARTIAL){
$message = "Une erreur est survenue lors de l'envoi du fichier, le serveur n'a reçu qu'une partie du fichier, veuillez réessayer à nouveau.";
}
elseif($file['error'] >= UPLOAD_ERR_NO_TMP_DIR){
$message = "Une erreur interne est survenue, veuillez réessayer à nouveau. Si le problème persiste, merci de contacter le support technique.";
}
// Here is the problem
$this->validationErrors[$field][] = $message;
return FALSE;
}
So far so good, my Validation rule seems to work correctly but when à get an error, I have two messages: "My custom message" and "This file cannot be left blank".
How to remove this message, where am I wrong?
Thanks in advance.
May be it will works for you
$this->validationErrors[$field][] = $message; // comment this Line
return FALSE // comment this Line
And Add the following line at last of your fileValidation function
return implode("\n", $message);
Cakephp.Saint's solution doesn't work because $message is a string, not an array but this works fine:
return $message;

Resources