Skip to Content Skip to Menu

CB Gallery file upload validation

  • activha
  • activha
  • OFFLINE
  • Posts: 2326
  • Thanks: 117
  • Karma: 13
2 months 3 days ago #338925 by activha
Replied by activha on topic CB Gallery file upload validation
Ok got it :-)

For the validation I have an issue which is that the trigger does not appear in the autoaction list. 
Tried to manually enter it but it does not validate.

My code is pretty simple 
Code:
$upload = $variables['var3']->getRaw( '_files' )->subTree( 'upload' ); $fileName = $upload->getString('name', '');     if (pathinfo($fileName, PATHINFO_EXTENSION) === 'csv') {         $filePath = $upload->getString('tmp_name', '');         $validationResult = validateCSV($filePath);         if (!$validationResult['status']) {             $variables['var3']->setError( 'ERROR_MESSAGE_HERE' );         }     } function validateCSV($filePath) {     if (($handle = fopen($filePath, 'r')) !== FALSE) {         $lineNumber = 0;         $columnCount = null;         while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {             $lineNumber++;             if ($columnCount === null) {                 $columnCount = count($data);             }             if (count($data) != $columnCount) {                 fclose($handle);                 return [                     'status' => false,                     'message' => "Le fichier CSV est mal formaté. Ligne $lineNumber a un nombre incorrect de colonnes."                 ];             }             foreach ($data as $field) {                 if (mb_detect_encoding($field, 'UTF-8', true) === false) {                     fclose($handle);                     return [                         'status' => false,                         'message' => "Le fichier CSV contient des caractères non UTF-8 à la ligne $lineNumber."                     ];                 }             }         }         fclose($handle);         return [             'status' => true,             'message' => "Le fichier CSV est bien formaté."         ];     } else {         return [             'status' => false,             'message' => "Impossible d'ouvrir le fichier."         ];     } }

User : automatic
No conditions, no output
So it should work with gallery_onBeforeCreateGalleryItem ?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
2 months 3 days ago #338926 by krileon
Replied by krileon on topic CB Gallery file upload validation

For the validation I have an issue which is that the trigger does not appear in the autoaction list.
Tried to manually enter it but it does not validate.

The list may not contain all triggers. Simply manually add it then press enter/return or click its entry in the dropdown. No idea what you mean by it didn't validate.

So it should work with gallery_onBeforeCreateGalleryItem ?

gallery_onBeforeCreateGalleryItem doesn't have any output so your returns will do nothing during it. See my previous reply where I've noted how to pass data to other views and my other reply for how to trigger errors.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • activha
  • activha
  • OFFLINE
  • Posts: 2326
  • Thanks: 117
  • Karma: 13
2 months 3 days ago #338927 by activha
Replied by activha on topic CB Gallery file upload validation
Ok I understand that at this point it doesn't have any output but it should not return the mini save window.

Using this trigger with only :
$upload = $variables->getRaw( '_files' )->subTree( 'upload' );
return;

it does not even stop the upload process.
Shouldn't the validation forbid the save ??

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
2 months 3 days ago #338928 by krileon
Replied by krileon on topic CB Gallery file upload validation
You need to set an error to stop the upload process. See my reply below where this is explained.

www.joomlapolis.com/forum/developer-members-support/246977-cb-gallery-file-upload-validation?start=0#338919


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum