0

I'm working on a registration module. The form has 3 parts, so users fills the first set of information, if everything's correct, he get's the second set and then the third. The first 2 are working fine but I'm facing issues with the 3rd one.

Here I take some information and files that needs to be uploaded. The form is pretty normal itself

<form method="post" action="domain.com/marketplace/seller/save">

Which remains same for all three forms. The first two works so I know this is right. My action is located in app/code/community/Manthan/Marketplace/controllers/SellerController.php. (Manthan is a marketplace extension) Inside, I have my action

public function saveAction()
    {
        $data = $this->getRequest()->getPost();
        <?php echo $this->__('save action') ?>
        if($data['formtype'] == 1){
          ...
        }else if($data['formtype'] == 2){
          ...
        }else if($data['formtype'] == 3){
            <?php echo $this->__('formtype 3') ?>
            try {               
                //print_r($_FILES);
                $user = Mage::getModel('admin/user')->getCollection()->addFieldToFilter('email', $data['email'])->getData();                
                $userId = $user['0']['user_id'];                                

                $sellercollection = Mage::getModel('marketplace/seller')->getCollection()
                                ->addFieldToFilter('user_id',$userId);                              
                $sellerId = $sellercollection->getFirstItem()->getId();

                $seller = Mage::getModel('marketplace/seller')->load($sellerId);                

                $dir_path = Mage::getBaseDir('media') . DS . 'marketplace' . DS . 'seller' . DS . 'images' . DS;

                if(isset($_FILES['pan']['name']) && $_FILES['pan']['name'] != '') 
                {
                   try
                   {    
                        $fileName       = $_FILES['pan']['name'];
                        $fileExt        = strtolower(substr(strrchr($fileName, ".") ,1));
                        $fileNamewoe    = rtrim($fileName, $fileExt);
                        $pan             =  preg_replace('/[^a-z0-9_\\-[:space:]]/i', '_', $fileNamewoe) . mt_rand(1000000000, 99999999999);                        
                        $pan        = $pan . '.' . $fileExt;

                        $uploader = new Varien_File_Uploader('pan');
                        $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'doc', 'docx', 'xls', 'xlsx'));
                        $uploader->setAllowRenameFiles(true);
                        $uploader->setFilesDispersion(false);
                        if(!is_dir($dir_path))
                            mkdir($dir_path, 0755, true);

                        $uploader->save($dir_path, $fileNamewithExt);
                        $seller->setPan($pan);
                    }
                    catch (Exception $e) 
                    {
                        Mage::getSingleton('adminhtml/session')->addError($e->getMessage());         
                    }
                }

                if(isset($_FILES['vat_tin_cst']['name']) && $_FILES['vat_tin_cst']['name'] != '') 
                {
                   try
                   {    
                        $fileName       = $_FILES['vat_tin_cst']['name'];
                        $fileExt        = strtolower(substr(strrchr($fileName, ".") ,1));
                        $fileNamewoe    = rtrim($fileName, $fileExt);
                        $vat_tin_cst       = preg_replace('/[^a-z0-9_\\-[:space:]]/i', '_', $fileNamewoe) . mt_rand(1000000000, 99999999999);                       
                        $vat_tin_cst= $vat_tin_cst . '.' . $fileExt;

                        $uploader = new Varien_File_Uploader('vat_tin_cst');
                        $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'doc', 'docx', 'xls', 'xlsx'));
                        $uploader->setAllowRenameFiles(true);
                        $uploader->setFilesDispersion(false);
                        if(!is_dir($dir_path))
                            mkdir($dir_path, 0755, true);

                        $uploader->save($dir_path, $fileNamewithExt);
                        $seller->setVatTinCst($vat_tin_cst);
                    }
                    catch (Exception $e) 
                    {
                        Mage::getSingleton('adminhtml/session')->addError($e->getMessage());         
                    }
                }

                if(isset($_FILES['cin']['name']) && $_FILES['cin']['name'] != '') 
                {
                   try
                   {    
                        $fileName       = $_FILES['cin']['name'];
                        $fileExt        = strtolower(substr(strrchr($fileName, ".") ,1));
                        $fileNamewoe    = rtrim($fileName, $fileExt);
                        $cin       = preg_replace('/[^a-z0-9_\\-[:space:]]/i', '_', $fileNamewoe) . mt_rand(1000000000, 99999999999);                       
                        $cin= $cin . '.' . $fileExt;

                        $uploader = new Varien_File_Uploader('cin');
                        $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'doc', 'docx', 'xls', 'xlsx'));
                        $uploader->setAllowRenameFiles(true);
                        $uploader->setFilesDispersion(false);
                        if(!is_dir($dir_path))
                            mkdir($dir_path, 0755, true);

                        $uploader->save($dir_path, $fileNamewithExt);
                        $seller->setCin($cin);
                    }
                    catch (Exception $e) 
                    {
                        Mage::getSingleton('adminhtml/session')->addError($e->getMessage());         
                    }
                }

                if(isset($_FILES['cancelled_cheque']['name']) && $_FILES['cancelled_cheque']['name'] != '') 
                {
                   try
                   {    
                        $fileName       = $_FILES['cancelled_cheque']['name'];
                        $fileExt        = strtolower(substr(strrchr($fileName, ".") ,1));
                        $fileNamewoe    = rtrim($fileName, $fileExt);
                        $cancelled_cheque       = preg_replace('/[^a-z0-9_\\-[:space:]]/i', '_', $fileNamewoe) . mt_rand(1000000000, 99999999999);                      
                        $cancelled_cheque= $cancelled_cheque . '.' . $fileExt;

                        $uploader = new Varien_File_Uploader('cancelled_cheque');
                        $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'doc', 'docx', 'xls', 'xlsx'));
                        $uploader->setAllowRenameFiles(true);
                        $uploader->setFilesDispersion(false);
                        if(!is_dir($dir_path))
                            mkdir($dir_path, 0755, true);

                        $uploader->save($dir_path, $fileNamewithExt);
                        $seller->setCancelledCheque($cancelled_cheque);
                    }
                    catch (Exception $e) 
                    {
                        Mage::getSingleton('adminhtml/session')->addError($e->getMessage());         
                    }
                }
                $seller->setBankName($data['panno']);
                $seller->setBankName($data['vat_tin_cstno']);
                $seller->setBankName($data['cinno']);
                $seller->setBankName($data['bank_name']);
                $seller->setBranchName($data['branch_name']);
                $seller->setBeneficiaryName($data['beneficiary_name']);
                $seller->setAccountNumber($data['account_number']);
                $seller->setTypeOfBankAccount($data['type_of_bank_account']);
                $seller->setIfscCode($data['ifsc_code']);
                $seller->save();

                //die('dd');
                //Mage::getSingleton('core/session')->addSuccess('Thank you for seller registration with us, we will contact you soon.');               
                Mage::getSingleton('core/session')->setSellerData(false);           
                $this->_redirect('thank-you-seller');   
            }
            catch (Mage_Core_Exception $e) {
                Mage::getSingleton('core/session')->addError($e->getMessage());
                Mage::getSingleton('core/session')->setSellerData($data);
                $this->_redirect('register');
                return $this;
            }
        }
    }

I removed the code for formdata 1 and 2 as they are working fine. I'm concerned with 3, as that is the condition that should be getting triggered this time.

So, what's happening is when I click submit on form 3, the files upload and the form submits but it takes me to a blank page domain.com/marketplace/seller/save. There's nothing in the html. I tried putting echo messages in the action but even those don't show up on the page. I've looked into the media folder and the files I selected in the form aren't there.

How do I test what's wrong here?

  • I think you have start php tan inside php code, have you check this in you code. – Suresh Chikani Oct 7 '16 at 6:07
0

Remove the <?php echo $this->__('save action') ?> these kind of code from the saveAction as you don't need to open a new <?php tag inside a method.

Also try something like below to check whether you are receiving the post data:

public function saveAction()
{
    $data = $this->getRequest()->getPost();
    print_r($data); die();
    //Other code here....
}
| improve this answer | |
  • Thanks Nidheesh. I didn't realize the php tags were already open. But I put up these tags to find out why the page was not working so that was another issue. The cause of real problem was another syntax error. In formtype 2 code I wrote Mage::getSingleton('core/session')->addSuccess('Almost There! We just need some Banking Information to Process your Funds. Then You're all set!');. The apostrophe in You're ended the string and the whole code below it broke. How stupid of me :p – VeeK Oct 7 '16 at 6:37

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.