Categories
Magento 2

Magento 2 – File or image upload via frontend custom module form and Controller

Today I will discuse how to File or image upload via frontend custom module form and Controller. Open your module form.phtml file and make sure that the form attribute method to post method=”post” and also make sure that the form attribute enctype like enctype=”multipart/form-data”.

Also make sure that INPUT field type attribute type=”file”, I have use file field name “filesubmission”.

Now open you costom module Controller php file VENDOR\MODULE\Controller\Index\Post.php and use some library class for DirectoryList, UploaderFactory and Filesystem in top of file below namespace.

Now add some protected on top of Controller class before __construct() method.

Now update your Controller method public function __construct() like below.

Now add code for fileupload in your Controller method public function execute(). You can see I do not use $_FILES Global Variable in Magento because it does not meet with Magento standards. Instead of $_FILES Variable please use $this->getRequest()->getFiles();

Here filesubmission is the input name and also the field name of database table.
Upload image file will be saved at pub/media/requestaquote directory.
And $data[‘filesubmission’] = $imagePath; the value of $imagePath; that will be saved in the database field.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE

Categories
Magento 2

Magento 2 – How to validate at least one checkbox in custom module form?

Today I will discuses, How to validate at least one checkbox in custom module form? Open your module form .phtml file and add the validation component on form tag, as a attribute like data-mage-init.

How to validate at least one checkbox in custom module form?

Add attribute on the form tag: data-mage-init='{“validation”:{}}’

Add some validation rules to your custom module form checkbox fields like data-validate=”{required:true, ‘validate-one-required-by-name’:true}”, Please see example checkbox form html code with validate-one-required-by-name below.

After form validate screen.

List of Magento 2 form validation rules

List of some Magento 2 validation rules you can use and their error message. You can find all methods yourself by looking in lib/web/prototype/validation.js on line 415

List of Magento 2 supported all form validation rules, jQuery validation rules

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE

Categories
Magento 2

Magento 2 – How to enable/disable WYSIWYG Editor?

In Magento 2 WYSIWYG Editor is an useful feature that allows users to directly see the appearence of the end result, helps users save a lot of time and produce greater results. In this tutorial, I will show you, How to enable/disable WYSIWYG Editor?

How to enable/disable WYSIWYG Editor?

Please follow this tutorial step by step how to enable/disable WYSIWYG Editor.

Step 1: Login into store admin and go to: STORES => Configuration page.

STORES => Configuration

Step 2: In the Configuration page go to General => Content Management to view WYSIWYG Options section.

Step 3: Enable WYSIWYG Editor is set to enable by default. Uncheck box “Use system value” and choose other option Disabled by default as shown in below picture.

 Enable WYSIWYG Editor

Click on “Save Config” button to save new changes.

Step 4: Finally, you need to clear cache by menu SYSTEM => Cache Management => Select All => Refresh => Submit

That’s all about How to enable/disable WYSIWYG Editor Magento 2 admin. Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE this post.

Categories
Magento 2

Magento 2 – Set page title by layout XML or Controller

By default URL showing as title but thats not good look that appears on the title bar when created a new custom module. There are 2 (two) ways of Set page title by layout XML or Controller.

1. From frontend view layout module_controller_action.xml by head and title tag.

2. From frontend view layout module_controller_action.xml by referenceBlock page.main.title and set setPageTitle argument tag.

Set page title by PHP Controller

Also we can set page title by PHP controller file controllerName.php in method public function execute()

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Laravel

Laravel 7.x Generate Database Seeding

Laravel: Generate Seeders

Laravel includes with a simple method of seeding your database with test data using seed classes. All seed classes are stored in the database/seeds directory. We can set any name for Seed classes, but we should follow some sensible convention, such as ProductsTableDataSeeder, etc. By default, a DatabaseSeeder class is defined for you. Using default class, you may use the call method to run other seed classes, allowing you to control the seeding order.

Creating a new module

We can creating a simple module by run the following command to create a module. Replace MODULE_NAME by your desired name.

Also we can create multiple modules in one command like below.

How to Generate Seeders?

We can generate a seeder by the Artisan command make:seeder. All of generated seeders class will be placed in the database/seeds directory:

Calling default DatabaseSeeder with Additional Seeders

Default the DatabaseSeeder class, you may use the call method to execute additional seed classes. Using the call method allows you to break up your database seeding into multiple files so that no single seeder class becomes overwhelmingly large. Enter the name of the seeder classes you want to run:

Laravel: Running Seeders

Once you have done generate your seeder, you may need to regenerate Composers autoloader using the dump-autoload command.

To seed your database now you may use the Artisan command db:seed. By default, the db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Laravel

Laravel 7.x Creating Table or Database Schema Migrations

Laravel: Database Migrations

Laravel database migrations are like version control for your database, allowing you to modify and share the application’s database schema. Laravel Schema facade provides database agnostic support for creating and manipulating tables across all of Laravel’s supported database systems.

How to create a migration?

We can create database migration by using the Artisan command make:migration New migration file be placed in project database/migrations directory. And each migration file name contains with timestamp, which allows Laravel to determine the order of the migrations.

Migration File Structure and Creating Table

Laravel migration class contains two methods: up and down. The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method. To create a new database table by using Schema::create method.

Run all Migrations

Please execute the migrate Artisan command to run all of your created migrations:

Roll Back or Refresh Migrate Using Artisan Command

Artisan migrate:refresh command will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Magento 2

Exception: Invalid template file: require_js.phtml in module: ‘Magento_Backend’ block’s name: ‘require.js’

To fix blank admin page on Magento 2.3 in Windows-10. This is the error what you will encounter when installing Magento 2.3 in Windows 10!

This error for the invalid template file is the difference between the use of “/” and “\” in the path. Windows uses “/” while Magento uses “\”.

The exception appear like this:

1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: ‘E:/xampp/htdocs/extendfeature/vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml’ in module: ‘Magento_Backend’ block’s name: ‘require.js’

Open file vendor\magento\framework\View\Element\Template\File\Validator.php line no 138. Of find isPathInDirectories function in line 133

And change line 138 from

To

After make change find isPathInDirectories function like below code.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Magento 2

Magento 2 Installation at 51% Error: (Wrong file in Gd2.php:64) Module ‘Magento_Theme’

I am having an issue during installing Magento 2 in localhost window10. I have updated my file like below and I can install in localhost. I am trying to solve by change on my php.ini

Also No UAC activate on WINDOWS 10 and Antivirus disabled. I have fetch the same error.

[ERROR]

InvalidArgumentException: Wrong file in E:\xampp\htdocs\extendfeature\vendor\magento\framework\Image\Adapter\Gd2.php:64 Stack trace: #0 E:\xampp\htdocs\extendfeature\vendor\magento\framework\Image.php(55): Magento\Framework\Image\Adapter\Gd2->open(‘E:/xampp/htdocs…’) #1 E:\xampp\htdocs\extendfeature\vendor\magento\framework\Image.php(36): Magento\Framework\Image->open() #2 E:\xampp\htdocs\extendfeature\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(121): Magento\Framework\Image->__construct(Object(Magento\Framework\Image\Adapter\Gd2), ‘E:/xampp/htdocs…’) #3 E:\xampp\htdocs\extendfeature\vendor\magento\framework\ObjectManager\Factory\Dynamic\Developer.php(66): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject(‘Magento\Framewo…’, Array) #4 E:\xampp\htdocs\extendfeature\vendor\magento\framework\ObjectManager\ObjectManager.php(56): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create(‘Magento\Framewo…’, Array) #5 E:\xampp\htdocs\extendfeature\vendor\magento\framework\Image\Factory.php(47): Magento\Framework\ObjectManager\ObjectManager->create(‘Magento\Framewo…’, Array) #6 E:\xampp\htdocs\extendfeature\vendor\magento\framework\View\Design\Theme\Image.php(127): Magento\Framework\Image\Factory->create(‘E:/xampp/htdocs…’) #7 E:\xampp\htdocs\extendfeature\vendor\magento\module-theme\Model\Theme\Registration.php(135): Magento\Framework\View\Design\Theme\Image->createPreviewImage(‘E:/xampp/htdocs…’) #8 E:\xampp\htdocs\extendfeature\vendor\magento\module-theme\Model\Theme\Registration.php(114): Magento\Theme\Model\Theme\Registration->_savePreviewImage(Object(Magento\Theme\Model\Theme\Data)) #9 E:\xampp\htdocs\extendfeature\vendor\magento\module-theme\Model\Theme\Registration.php(73): Magento\Theme\Model\Theme\Registration->_registerThemeRecursively(Object(Magento\Theme\Model\Theme\Data)) #10 E:\xampp\htdocs\extendfeature\vendor\magento\module-theme\Setup\Patch\Data\RegisterThemes.php(47): Magento\Theme\Model\Theme\Registration->register() #11 E:\xampp\htdocs\extendfeature\vendor\magento\framework\Setup\Patch\PatchApplier.php(162): Magento\Theme\Setup\Patch\Data\RegisterThemes->apply() #12 E:\xampp\htdocs\extendfeature\setup\src\Magento\Setup\Model\Installer.php(1023): Magento\Framework\Setup\Patch\PatchApplier->applyDataPatch(‘Magento_Theme’) #13 E:\xampp\htdocs\extendfeature\setup\src\Magento\Setup\Model\Installer.php(890): Magento\Setup\Model\Installer->handleDBSchemaData(Object(Magento\Setup\Module\DataSetup), ‘data’, Array) #14 [internal function]: Magento\Setup\Model\Installer->installDataFixtures(Array) #15 E:\xampp\htdocs\extendfeature\setup\src\Magento\Setup\Model\Installer.php(371): call_user_func_array(Array, Array) #16 E:\xampp\htdocs\extendfeature\setup\src\Magento\Setup\Controller\Install.php(109): Magento\Setup\Model\Installer->install(Array) #17 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-mvc\src\Controller\AbstractActionController.php(83): Magento\Setup\Controller\Install->startAction() #18 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-eventmanager\src\EventManager.php(321): Laminas\Mvc\Controller\AbstractActionController->onDispatch(Object(Laminas\Mvc\MvcEvent)) #19 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-eventmanager\src\EventManager.php(178): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent), Object(Closure)) #20 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-mvc\src\Controller\AbstractController.php(115): Laminas\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Laminas\Mvc\MvcEvent)) #21 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-mvc\src\DispatchListener.php(117): Laminas\Mvc\Controller\AbstractController->dispatch(Object(Laminas\Http\PhpEnvironment\Request), Object(Laminas\Http\PhpEnvironment\Response)) #22 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-eventmanager\src\EventManager.php(321): Laminas\Mvc\DispatchListener->onDispatch(Object(Laminas\Mvc\MvcEvent)) #23 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-eventmanager\src\EventManager.php(178): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent), Object(Closure)) #24 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-mvc\src\Application.php(339): Laminas\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Laminas\Mvc\MvcEvent)) #25 E:\xampp\htdocs\extendfeature\setup\index.php(39): Laminas\Mvc\Application->run() #26 {main} Next Magento\Framework\Setup\Exception: Unable to apply data patch Magento\Theme\Setup\Patch\Data\RegisterThemes for module Magento_Theme. Original exception message: Wrong file in E:\xampp\htdocs\extendfeature\vendor\magento\framework\Setup\Patch\PatchApplier.php:170 Stack trace: #0 E:\xampp\htdocs\extendfeature\setup\src\Magento\Setup\Model\Installer.php(1023): Magento\Framework\Setup\Patch\PatchApplier->applyDataPatch(‘Magento_Theme’) #1 E:\xampp\htdocs\extendfeature\setup\src\Magento\Setup\Model\Installer.php(890): Magento\Setup\Model\Installer->handleDBSchemaData(Object(Magento\Setup\Module\DataSetup), ‘data’, Array) #2 [internal function]: Magento\Setup\Model\Installer->installDataFixtures(Array) #3 E:\xampp\htdocs\extendfeature\setup\src\Magento\Setup\Model\Installer.php(371): call_user_func_array(Array, Array) #4 E:\xampp\htdocs\extendfeature\setup\src\Magento\Setup\Controller\Install.php(109): Magento\Setup\Model\Installer->install(Array) #5 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-mvc\src\Controller\AbstractActionController.php(83): Magento\Setup\Controller\Install->startAction() #6 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-eventmanager\src\EventManager.php(321): Laminas\Mvc\Controller\AbstractActionController->onDispatch(Object(Laminas\Mvc\MvcEvent)) #7 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-eventmanager\src\EventManager.php(178): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent), Object(Closure)) #8 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-mvc\src\Controller\AbstractController.php(115): Laminas\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Laminas\Mvc\MvcEvent)) #9 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-mvc\src\DispatchListener.php(117): Laminas\Mvc\Controller\AbstractController->dispatch(Object(Laminas\Http\PhpEnvironment\Request), Object(Laminas\Http\PhpEnvironment\Response)) #10 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-eventmanager\src\EventManager.php(321): Laminas\Mvc\DispatchListener->onDispatch(Object(Laminas\Mvc\MvcEvent)) #11 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-eventmanager\src\EventManager.php(178): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent), Object(Closure)) #12 E:\xampp\htdocs\extendfeature\vendor\laminas\laminas-mvc\src\Application.php(339): Laminas\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Laminas\Mvc\MvcEvent)) #13 E:\xampp\htdocs\extendfeature\setup\index.php(39): Laminas\Mvc\Application->run() #14 {main}

Solutions:

Finally Installation is complete 100% after done following changes:

Find validateURLScheme function in vendor\magento\framework\Image\Adapter\Gd2.php file. at line 96. Replace function with this: !file_exists($filename)

Please find and change validateURLScheme function like below code.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE