Jump to content

how to add an input file uploader in customer registration form


Safwen

Recommended Posts

Hi guys ,

 

what i want to do is to add an input image uploader in user registration form to allow customers to upload an profil image. 

i added an input file in the file authentication.tpl  under the birthday tag like that : 

<div class="control-group">
			<label class="control-label" for="image_lab">{l s='Image Profile'} <sup>*</sup></label>
            <div class="controls">
                <input type="file" name="image" id="image" />
            </div>
		</div>

i added the enctype in the form tag like that : 

<form action="{$link->getPageLink('authentication', true)}" method="post" id="account-creation_form" class="std form-horizontal" enctype= "multipart/form-data">

now in authController.php i want to retrieve the uploaded image and to place it under a folder named profil under the img folder  and to name it with the id of the customer that will be created 

eg : if the id affected to the customer will be 12 the image should be placed in img/profil/12.jpg

 

how to do that in authController.php ? where to place the code exactly ?

 

can anyone help me please ? thank you in advance.

Link to comment
Share on other sites

this is the PHP code but i don't know where to place it in AuthController.php

if( Tools::isSubmit('submitAccount'))
		{
			
			$nom = $_POST['email'];
			
						$uploads_dir = 'img/miniatures/';
						chmod($uploads_dir, 770);
						$tmp_name = $_FILES["image"]["tmp_name"];
						chmod($_FILES['image']['tmp_name'], 770);
						$name = $_FILES["image"]["name"];
						
						move_uploaded_file($tmp_name, $uploads_dir.$nom.".jpg");
					
				
		}
Link to comment
Share on other sites

  • 1 year later...

I want to add an input file uploader in customer registration form in Prestashop v1.6 as well. This document is required to account creation.I'm stuck for days.. I've added lines to authentification.tpl around line 131 like this :

<div class="required form-group">                  <label for="carte_pro">{l s='Upload Professionnal card :'}<sup>*</sup></label>                <input type="file" class="is_required validate form-control" data_validate="isFichiercorrect" id="carte_pro" name="carte_pro" value="{if isset($smarty.post.carte_pro)}{$smarty.post.carte_pro}{/if}" />                <p>{l s='Valid extensions are doc,pdf,jpg,jpeg and png.'}</p>                               </div>

Then around line 464 :

<div class="required form-group">            <label for="carte_pro">{l s='Upload Professionnal card :'} <sup>*</sup></label>            <input onkeyup="$('#carte_pro').val(this.value);" type="file" class="is_required validate form-control" data-validate="isFichiercorrect" id="customer_carte_pro" name="carte_pro" value="{if isset($smarty.post.carte_pro)}{$smarty.post.carte_pro}{/if}" />        </div>      

Then I overrided customer.php by ading thoses lines : around line 30 : public$carte_pro; and around line 68 : 'carte_pro' => array('type' => self::TYPE_STRING, 'validate' => 'isFichiercorrect', 'required' => true, 'size' => 128),

Then I overrided the Validate.php file by adding at the end :

** * Validation carte_pro * @static */public static function isFichiercorrect($carte_pro){    return preg_match('/^[a-zA-Z0-9_.-]+$/', $name);}

I precise that i generated inbetween an Sql request to create my field like this :ALTER TABLE ps_customer ADDcarte_proVARCHAR(128) NOT NULL The thing is, that nothing really works. I'd appreciate your precious help considering that I've past so many hours to solve this..I would be great to be notified in back office and able to display there the document..Please help xx

Link to comment
Share on other sites

What is your main goal here? You want the user to upload an image as a profile image like we have here on the forums? 

 

What I'm missing in your posts is the part where you show the PS core that this field is part of the actual model (Customer.php). 

 

See: https://github.com/PrestaShop/PrestaShop/blob/1.6/classes/Customer.php#L157

 

If you add your field there, the core will know this field is available and can be updated / changed :-)

 

PS: Don't forget to turn the 'classes override' on in the backoffice.

Link to comment
Share on other sites

Hi,

 

Thanks for answering.

My purpose is not to create an avatar image; I want the visitors to upload a document (word ou pdf or png or jpg) to proove that they are real professionnals.

Once I'll receive their document, I'll be able to validate their account creation and allow them to access content of the webiste.

Do you get it ? how can I tunr this override on in back office ?

Link to comment
Share on other sites

  • 1 year later...

Safwen where did you put the php code?

if( Tools::isSubmit('submitAccount'))
        {
            
            $nom
= $_POST['email'];
            
                        $uploads_dir
= 'img/miniatures/';
                        chmod($uploads_dir, 770);
                        $tmp_name = $_FILES["image"]["tmp_name"];
                        chmod($_FILES['image']['tmp_name'], 770);
                        $name = $_FILES["image"]["name"];
                        
                        move_uploaded_file
($tmp_name, $uploads_dir.$nom.".jpg");
                    
                
        
}


i want to make a primary photo in my customer account, can anyone help me?

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...