1

When I submit data to saveprofile.php (controller).

saveprofile.php

use Magento\Authorization\Model\UserContextInterface as UserContextInterface;
use Magento\Authorization\Model\Acl\Role\User as RoleGroup;
use Magento\Framework\Message\ManagerInterface;
use Medma\MarketPlace\Model\ProfileFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Backend\App\Action;

class Saveprofile extends \Magento\Framework\App\Action\Action
{

   /**
    * @var \Magento\Config\Model\Config\Factory
    */
    protected $scopeConfig;

   /**
    * @var \Medma\MarketPlace\Model\ProfileFactory
    */
    protected $profile;

   /**
    * @var Magento\Framework\Message\ManagerInterface
    */
    protected $messageManager;

   /**
    * @var \Magento\Authorization\Model\RoleFactory
    */
    protected $rolesFactory;

   /**
    * @var \Medma\MarketPlace\Helper\Data
    */
    protected $marketHelper;

   /**
    * @var \Magento\MediaStorage\Model\File\UploaderFactory
    */
    protected $_fileUploaderFactory;

   /**
    * @var \Magento\Framework\Registry
    */
    protected $coreregistry;

   /**
    * @var \Magento\Framework\Session\SessionManager
    */
    protected $session;

    /**
     *
     * @param \Magento\Framework\App\Action\Context $context,
     * @param \Magento\Framework\Registry $coreregistry,
     * @param \Magento\User\Model\UserFactory $adminuser,
     * @param \Medma\MarketPlace\Helper\Data $marketHelper,
     * @param \Magento\Authorization\Model\RoleFactory $rolesFactory,
     * @param \Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
     * @param \Magento\Framework\Session\SessionManager $session,
     * @param \Medma\MarketPlace\Model\ProfileFactory $profile,
     * @param \Magento\Config\Model\Config\Factory $scopeConfig,
     * @param \Magento\Framework\Message\ManagerInterface $messageManager
     *
     */

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\Registry $coreregistry,
        \Magento\User\Model\UserFactory $adminuser,
        \Medma\MarketPlace\Helper\Data $marketHelper,
        \Magento\Authorization\Model\RoleFactory $rolesFactory,
        \Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
        \Magento\Framework\Session\SessionManager $session,
        ProfileFactory $profile,
        \Magento\Config\Model\Config\Factory $scopeConfig
    ) {
        $this->profile = $profile;
        $this->coreregistry = $coreregistry;
        $this->session = $session;
        $this->rolesFactory = $rolesFactory;
        $this->messageManager = $context->getMessageManager();
        $this->ModelUser = $adminuser;
        $this->marketHelper = $marketHelper;
        $this->_fileUploaderFactory = $fileUploaderFactory;
        $this->scopeConfig = $scopeConfig;
        parent::__construct($context);
    }

    public function execute()
    {

        $post = $this->getRequest()->getParams();
        $this->session->setVendorData($post);
        $model = $this->profile->create();
        $total_file_upload = $this->getRequest()->getParam('total_file_upload', false);
        $h="String";
        return $h;

    //     if ($post) {
    //         try {
    //             $data = [];
    //             $data = $post;

    //             if ($data['password']!=$data['confirmation']) {
    //                 $this->messageManager->addError(__("Entered confirm password do not matches the password"));
    //                 $this->_redirect($this->_redirect->getRefererUrl());
    //                 return;
    //             }

    //             $uploaded_files = [];
    //             $fileId = 'file';

    //               /**
    //              * Check files allowed
    //              **/

    //             $file_types = $this->marketHelper->getConfig('vendor_registration', 'files_allowed');
    //             $file_types = str_replace(' ', '', $file_types);
    //             $file_types_array = array_map('trim', explode(',', $file_types));


    //             /*
                //  * Check max allowed file size
                //  */


    //             $max_allowed_file_size = $this->marketHelper->getConfig('vendor_registration', 'max_allowed_file_size');
    //             $max_allowed_file_size_bytes = ($max_allowed_file_size * 1024 * 1024);


    //             /*
                //  * UPLOAD verification proof FILES
                //  */

    //             $uploaded_files = [];
    //             for ($i = 1; $i <= $total_file_upload; $i++) {
    //                 $file_control_name = 'varification_proof_' . $i;

    //                 $uploader = $this->_fileUploaderFactory->create(['fileId' => $file_control_name]);
    //                 $arr = $uploader->validateFile();


    //                 $arr[$file_control_name]['name'] = str_replace(' ', '', $arr['name']);
    //                 $arr[$file_control_name]['name'] = date("YmdHis")."-".$arr['name'];


    //                 if (isset($arr[$file_control_name]['name']) && $arr[$file_control_name]['name'] != '') {
    //                     if ($arr['size'] > $max_allowed_file_size_bytes) {
    //                         $this->messageManager->addError(__('File size should not exceed ' . $max_allowed_file_size .  ' Mb'));
    //                         $this->_redirect($this->_redirect->getRefererUrl());
    //                         return;
    //                     }

    //                     try {
    //                         $f_type=$arr['type'];
    //                         if ($f_type!= "image/gif" && $f_type!= "image/png" && $f_type!= "image/jpeg" && $f_type!= "image/JPEG" && $f_type!= "image/PNG" && $f_type!= "image/GIF") {
    //                             $this->messageManager->addError(__('Disallowed File Type'));
    //                             $this->_redirect($this->_redirect->getRefererUrl());
    //                             return;
    //                         }

    //                         $dir_path = $this->marketHelper->getImagesDir('varifications');

    //                         $uploader = $this->_fileUploaderFactory->create(['fileId' => $file_control_name]);

    //                         $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
    //                         $uploader->addValidateCallback('validate', $this, 'validateFile');

    //                         $uploader->setAllowRenameFiles(false);

    //                         $uploader->setFilesDispersion(false);

    //                         $uploader->save($dir_path, $arr[$file_control_name]['name']);
    //                     } catch (\Magento\Framework\Validator\Exception $e) {
    //                         $this->messageManager->addError($e->getMessage());
    //                         $this->_redirect($this->_redirect->getRefererUrl());
    //                         return;
    //                     }
    //                     $uploaded_files[] = $arr[$file_control_name]['name'];
    //                 }
    //             }

    //             $roleId = $this->marketHelper->getConfig('general', 'vendor_role');

    //             $varification_files = json_encode($uploaded_files);


    //             /**
    //              * Set Data in admin user table
    //              *
    //              **/
    //             $adminuser = $this->ModelUser->create();
    //             $adminuser = $adminuser->setUsername($data['username'])
    //                                   ->setFirstname($data['firstname'])
    //                                   ->setLastname($data['lastname'])
    //                                   ->setEmail(strtolower($data['email']))
    //                                   ->setIsActive(0);

    //             /**
    //              * Set Data in authorization table
    //              *
    //              **/

    //             $role=$this->rolesFactory->create();
    //             $role->setRoleName($data['username'])
    //                  ->setRoleType(RoleGroup::ROLE_TYPE)
    //                  ->setParentId($roleId)
    //                  ->setTreeLevel(2)
    //                  ->setUserType(UserContextInterface::USER_TYPE_ADMIN);

    //             try {
    //                 if ($data['password']) {
    //                     $adminuser->setPassword($data['password']);
    //                     $result = $adminuser->validate();
    //                     $adminuser->save();
    //                     $id = $adminuser->getUserId();
    //                     $role->setUserId($id);
    //                     $role->save();
    //                 }
    //             } catch (\Magento\Framework\Validator\Exception $e) {
    //                 $this->messageManager->addError($e->getMessage());
    //                 $this->_redirect($this->_redirect->getRefererUrl());
    //                 return;
    //             }


    //             if (is_array($result)) {
    //                 $this->adminSession->setUserData($data);
    //                 foreach ($result as $message) {
    //                     $this->messageManager->addError($message);
    //                 }
    //                 $this->_redirect($this->_redirect->getRefererUrl());
    //                 return;
    //             } else {

    //                 /**
    //                  * Set Data in Marketplace Profile Table
    //                  *
    //                  **/

    //                 $data["user_id"] = $id;
    //                 $data["shop_name"] = $post["shop_name"];
    //                 $data["contact_number"] = $post["contact_number"];
    //                 $data["country"] = $post["country"];
    //                 $data["latitude"] = $post["latitude"];
    //                 $data["longitude"] = $post["longitude"];
    //               // $data["age_name"] = $post["age_name"];
    //                 $data["vendor_industry"] = $post["vendor_industry"];
    //                 $data["vendor_scorecard"] = $post["vendor_scorecard"];
    //                  /**
    //                  * Verification Files Uploaded
    //                  *
    //                  **/
    //                 if (count($uploaded_files)>0) {
    //                     $data["proof_type"] = $post["proof_type"];
    //                     $data["varification_files"] = json_encode($uploaded_files);
    //                 }


    //                 $data["create_date"] = date("Y-m-d H:i:s");
    //                 $data["total_admin_commission"] = 0;
    //                 $data["total_vendor_amount"] = 0;
    //                 $data["total_vendor_paid"] = 0;

    //                 $model = $this->profile->create();

    //                 $model->setData($data);

    //                 /*
    //                  * Send Email
    //                  * */

    //                 $receiverInfo = [
    //                 'name' => $data['firstname'],
    //                 'email' => $data['email']
    //                 ];


    //                 try{
    //                 /* Sender Detail  */
    //                 if ($this->marketHelper->getConfig('vendor_registration_email', 'enable_registration_email')==1) {
    //                      $reciever = $this->marketHelper->getTemplateId('marketplace/vendor_registration_email/email_receiver');
    //                      $receivername = $this->marketHelper->getTemplateId('trans_email/ident_'.$reciever.'/name');
    //                      $receiveremail = $this->marketHelper->getTemplateId('trans_email/ident_'.$reciever.'/email');
    //                      $sendername = $this->marketHelper->getTemplateId('trans_email/ident_general/name');
    //                      $senderemail = $this->marketHelper->getTemplateId('trans_email/ident_general/email');


    //                      $receiverInfo = [
    //                      'name' => $receivername,
    //                      'email' => $receiveremail,
    //                      ];
    //                      $senderInfo = [
    //                      'name' => $sendername,
    //                      'email' => $senderemail,
    //                      ];

    //                      $emailTemplateVariables = [];
    //                      $emailTempVariables['myvar1'] = $data['firstname'].' '.$data['lastname'];
    //                      $emailTempVariables['myvar2'] = $receivername;

    //                      $this->marketHelper->sendRegistrationEmailToVendor(
    //                          $emailTempVariables,
    //                          $senderInfo,
    //                          $receiverInfo
    //                      );

    //                  }
    //                  /** 
    //                   * send email to vendor
    //                  */
    //                  if ($this->marketHelper->getConfig('registration_confirmation_email', 'active_vendor_email')==1) {
    //                      $vendorSender = $this->marketHelper->getTemplateId('marketplace/registration_confirmation_email/email_sender');
    //                      $vendorsendername = $this->marketHelper->getTemplateId('trans_email/ident_'.$vendorSender.'/name');
    //                      $vendorsenderemail = $this->marketHelper->getTemplateId('trans_email/ident_'.$vendorSender.'/email');

    //                      $vendorReceiverInfo = [
    //                      'name' => $data['firstname'],
    //                      'email' => $data['email']
    //                      ];
    //                      $vendorSenderInfo = [
    //                      'name' => $vendorsendername,
    //                      'email' => $vendorsenderemail,
    //                      ];

    //                      $vendorEmailTemplateVariables = [];
    //                      $vendorEmailTemplateVariables['vendorname'] = $data['firstname'];

    //                      $this->marketHelper->sendConfirmationEmail(
    //                          $vendorEmailTemplateVariables,
    //                          $vendorSenderInfo,
    //                          $vendorReceiverInfo
    //                      );

    //                  }
    //              }catch (\Exception $e) {
    //                     $this->messageManager->addError($e->getMessage());

    //               }
    //                 $model->save();

    //                 $this->messageManager->addSuccess(__('Request has been sent successfully, we will contact you soon.'));
    //                 $this->_redirect($this->_redirect->getRefererUrl());
    //             }
    //         } catch (\Magento\Framework\Validator\Exception $e) {
    //             $this->messageManager->addError($e->getMessage());
    //             $this->_redirect($this->_redirect->getRefererUrl());
    //             return;
    //         }
    //     }
    //     $this->_redirect($this->_redirect->getRefererUrl());
    }
}

But all ways showing

This page isn’t working www.mg.project.co didn’t send any data.
ERR_EMPTY_RESPONSE

Error not showing on this page

How I can fix the issue

I already tried

1) index.php

 error_reporting(E_ALL); 
 ini_set('display_errors', 1);

2) The project already in developer mode:

enter image description here

Post request not working why???

Post request image

  • You should first check whether your controller execute method getting called or not. You can put all code in comment and just check by printing something that method called or not. If called, try uncommenting code one by one so you can find the culprit. If method is not called then it might be issue with routes.xml file – Khushbu Jun 11 at 8:53
  • @prabhakaran7 check in app/bootstrap.php there you should uncomment ini_set('display_errors', 1); – Ansar Husain Jun 11 at 8:56
  • @Khushbu it's going to that page but when again i remove comment it's not working – prabhakaran7 Jun 11 at 9:50
  • @prabhakaran7 you have to debug your code and find out which exact line of code is causing issue. you can share here that line so we can help – Khushbu Jun 11 at 10:03
4

if you're using Apache as a web server you can display error from apache error.log to your browser with adding this line code to your root .htaccess.

php_flag  display_errors                  on
php_flag  display_startup_errors          on
  • controller not working bro – prabhakaran7 Jun 11 at 12:59
  • when i click on submit showing this error ERR_EMPTY_RESPONSE – prabhakaran7 Jun 11 at 13:01
  • In my post request has no status code (like 404,500) – prabhakaran7 Jun 11 at 14:27
  • I always use this method to show error when php execution get error and it's work for me, but you could check the error log manually on /var/log/apache2/error.log file to make sure what issue you are having. – mrfizh Jun 11 at 16:28
  • updated one image (post req) – prabhakaran7 Jun 12 at 4:34
2

You are doing wrong in the following line

 $h="String";
 return $h;

You should redirect this page to any destination or you should print the response.

Solution 1. Change return $h; to echo $h;

Solution 2. Change return $h; to $this->_redirect($this->_redirect->getRefererUrl());

Please mark the answer if it works for you.

  • $this->_redirect($this->_redirect->getRefererUrl()); what is this line actully do – prabhakaran7 Jun 11 at 12:02
  • This will redirect the page to the referrer page (page from you hit the controller).You can pass your own url to redirect to specific page like home page or any thank you page. – Ashvini Marwal Jun 11 at 12:04
  • are you running company w3ctrl ........ – prabhakaran7 Jun 11 at 12:06
  • i was working with w3ctrl.please mark answer if it's working for you. – Ashvini Marwal Jun 11 at 12:07
  • when i uncomment all code it's not working – prabhakaran7 Jun 11 at 12:17
1

Go to your root directory and open .htaccess file.

Add the following code:

php_flag  display_errors                  on
php_flag  display_startup_errors          on

var/log/system.log Here, you can check the error which you are facing.

  • max_execution_time 180 is that ok – prabhakaran7 Jun 11 at 9:37
  • @prabhakaran7, max_execution_time 2400. go for it and check with it – Teja Bhagavan Kollepara Jun 11 at 10:14
  • still i'm facing that issue bro..... – prabhakaran7 Jun 11 at 10:21
  • Restart server, clear cache, reindex all – Teja Bhagavan Kollepara Jun 11 at 10:22
  • In my post request has no status code (like 404,500) – prabhakaran7 Jun 11 at 14:28
0

Magento_Root/app/bootstrap.php

Line no. 12

remove # from this line:

ini_set('display_errors', 1);

After this you will get the error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.