Jump to content

Problem with function postProcess on submit form


Recommended Posts

Hello,

 

I'm developping a module which is kind of simple. I just get information for an object in BO and I show them on FO.

 

To get all the information, I created an AdminClassController with basic function (renderForm, renderList, renderView). It's working great.
 

My problem: I would like to add the possibility to upload image for each object. So in my Class.php file I created a var string which is the path of my image and in the renderForm I added the file type input.

 

Then I use the postProcess function to upload the file on FTP :

       public function postProcess()
	    {
	    	if(Tools::isSubmit('saveAction')) {

	    		if (!($obj = $this->loadObject(true)))
					return;

	    		$path = $_FILES['logo']['name'];
	    		$path2 = $_FILES['image']['name'];

	    		$ext = pathinfo($path, PATHINFO_EXTENSION);
	    		$ext2 = pathinfo($path2, PATHINFO_EXTENSION);

	    		if ($ext == 'jpg' || $ext == 'png' || $ext == 'jpeg') {
	    			Db::getInstance()->Execute("UPDATE `"._DB_PREFIX_."annuaire` SET logo_path = 'logo_".$obj->id.'.'.$ext."' WHERE id_annuaire = ".$obj->id."");
	    			move_uploaded_file($_FILES["logo"]["tmp_name"], _PS_MODULE_DIR_.'annuaire/img/logo_'.$obj->id.'.'.$ext);	
	    		}

	    		if ($ext2 == 'jpg' || $ext2 == 'png' || $ext == 'jpeg') {
	    			Db::getInstance()->Execute("UPDATE `"._DB_PREFIX_."annuaire` SET image1_path = 'image_".$obj->id.'.'.$ext2."' WHERE id_annuaire = ".$obj->id."");
	    			move_uploaded_file($_FILES["image"]["tmp_name"], _PS_MODULE_DIR_.'annuaire/img/image_'.$obj->id.'.'.$ext2);	
	    		}     		
	    	}

	    	// !!!! return parent::postProcess(); !!!! //
	   

The issue is when I wrtie the line "return parent::postProcess();", I can update all passed input (text, select,...) and when I don't write it, my DB doesn't update and the file isn't uploaded.

 

Have you an hint top help me with this ?

 

Thanks for any help,

Regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...