Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

photo field in customer registration and edit error
 
man_in_black
Jr. Member
 
Total Posts:  21
Joined:  2012-02-14
 

Below i have added the code to upload photo. Well i have added photo upload in edit.phtml page only but in register.phtml magento showing error. Can anyone fix it ?

error message : Wrong entity ID.

and i guess there are so many other problems in the code as well so anybody can fix it ?

app/design/frontend/default/blue/template/customer/form/register.phtml

<?php        
$setup 
= new Mage_Eav_Model_Entity_Setup('core_setup');
$attr2 = array (
'position' => 1,
'is_required'=>
);
$setup->addAttribute(’61’‘photo’$attr2);
?>

app/design/frontend/default/blue/template/customer/form/edit.phtml

<li class="field">
                <
label for="photo" class="required " ><?php echo $this->__('Photo'?></label>
                <
div class="required-entry input-text">
                    <
input type="file" name="photo" id="photo" value="<?php echo $this->htmlEscape($this->getCustomer()->getPhoto()) ?>" title="<?php echo $this->__('Photo') ?>" class="required-entry input-text" />
                </
div>

app/code/core/Mage/Customer/Model/Entity/Setup.php

'photo' => array(
                    
'label'         => 'Photo1',
                    
'required'      => false,
                    
'sort_order'    => 61,
                     ),

app/code/core/Mage/Customer/etc/config.xml

<photo1><create>1</create><update>1</update></photo1>
app/code/core/Mage/Customer/controllers/AccountController.php

$logoName '';
if (isset(
$_FILES['photo']['name']) && $_FILES['photo']['name'!= ''{
try {
$uploader 
= new Varien_File_Uploader(‘photo1‘);
$uploader->setAllowedExtensions(array(‘jpg’,’jpeg’,’gif’,’png’));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path Mage::getBaseDir(‘media’) . DS.’customer’.DS;
$logoName $_FILES['photo']['name'];
$uploader->save($path$logoName);

catch (Exception $e{

}
}

if (!$customer Mage::registry(‘current_customer’)) {

$customer 
Mage::getModel(‘customer/customer’)
->
setEmail($this->getRequest()->getPost(‘email’))
->
setPhoto($logoName//Add this
->setPassword($this->getRequest()->getPost(‘password’))
->
setConfirmation($this->getRequest()->getPost(‘confirmation’))
->
setId(null);
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Hello
This is your problem.

<?php        
$setup 
= new Mage_Eav_Model_Entity_Setup('core_setup');
$attr2 = array (
'position' => 1,
'is_required'=>
);
$setup->addAttribute(’61’‘photo’$attr2);
?>
If you are using it to add a the photo attribute you are doing it wrong.
You should create a custom module with database support. (see this for more details)

If you want to do it quick and dirty, but I strongly DO NOT recommend it (and I’m not sure it will work) try replacing this:

$setup->addAttribute(’61’‘photo’$attr2);
with this
$setup->addAttribute(’customer’‘photo’$attr2);
By the way, where did you get that 61?

Cheers,
Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
 
man_in_black
Jr. Member
 
Total Posts:  21
Joined:  2012-02-14
 

now there is no error but still can’t find the problem no database no upload

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

What do you mean by ‘no database no upload’?
Did you set the enctype="multipart/form-data" for the registration and customer edit form?

 
Magento Community Magento Community
Magento Community
Magento Community
 
man_in_black
Jr. Member
 
Total Posts:  21
Joined:  2012-02-14
 

well yes for the edit page only . I didn\’t do it for registration page. do i need to add it to register page as well ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

If you don’t use it in the registration page then you don’t need it.
But I don’t understand what is your problem. What doesn’t work?

 
Magento Community Magento Community
Magento Community
Magento Community
 
man_in_black
Jr. Member
 
Total Posts:  21
Joined:  2012-02-14
 

well for getting the photo data i have used the comment :

$resource Mage::getSingleton('core/resource');
$readConnection $resource->getConnection('core_read');
$customer_data Mage::getModel('customer/customer')->load(Photo);
$photo $customer_data->getPhoto();

But i am not getting any results ?

can you tell me where should i put the in the register.phtml page
i paste it just before the form action is it current ?

<?php
/**
 * Create account form template
 *
 * @see Mage_Customer_Block_Form_Register
 */
?>
<div class="account-create">
    <
div class="page-title">
        <
h1><?php echo $this->__('Create an Account'?></h1>
         <
div class="titlebot"></div>
    </
div>

    <
div  class="account-toptxt clearfix">

     <
span class="requiredfield "><?php echo $this->__('* Required Fields'?></span>
    </
div>
   
           
            <!--<
class="back-link"><a href="<?php //echo $this->getBackUrl() ?>" class="back-link"><small>&laquo; </small><?php //echo $this->__('Back') ?></a></p>-->
 
<?php            
$setup 
= new Mage_Eav_Model_Entity_Setup('core_setup');
$attr2 = array (
'position' => 1,
'is_required'=>0
);
$setup->addAttribute('customer''photo'$attr2); 
?>

is that ok ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

I don’t think you understand what this does:

<?php            
$setup 
= new Mage_Eav_Model_Entity_Setup('core_setup');
$attr2 = array (
'position' => 1,
'is_required'=>0
);
$setup->addAttribute('customer''photo'$attr2); 
?>
This should add your attribute in the database for the customer entity. And you are still missing some key meta-data about your attribute (type)
It’s not a good idea to add it in a .phtml file. This means Magento will try to add it every time you run that specific page (register in your case).

Like I said in one of my previous posts, create a custom module that adds the ‘photo’ attribute to the customer entity. When you are sure that the attribute is added (look in the eav_attribute table for the record with the highest ID) then try to add the html for the input and the code in the controller to handle it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
man_in_black
Jr. Member
 
Total Posts:  21
Joined:  2012-02-14
 

well i am very new with magento so i don’t know much about it. Well let me explain.

i found it so that means it has been created ?

(5641'photo'NULL'''varchar''''''text'''''''10''0'');

Now when i upload photo from the edit page the photo is uploading everything is fine but where is it the database ? in which folder it is uploading ? for what customer it is added ? i can’t find anything

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

now we are getting somewhere.
It should be uploaded in media/customer. You set it like that:

$path Mage::getBaseDir(‘media’) . DS.’customer’.DS;
The reference to it should appear in the table customer_entity_varchar (it should have the attribute_id 564).
In the same table you should find the customer id for which is been uploaded. (field entity_id).
 
Magento Community Magento Community
Magento Community
Magento Community
 
man_in_black
Jr. Member
 
Total Posts:  21
Joined:  2012-02-14
 

well, i couldn’t find anything in the database even not in the folder it means nothing is updating. I am not getting any error in the codes but no updates in database even no image in the folder

 
Magento Community Magento Community
Magento Community
Magento Community
 
kondrei
Jr. Member
 
Total Posts:  1
Joined:  2012-04-04
 

I want to add a field to registration too but i have a problem:
I use the Queldorei theme and Magento 1.7.0.2
My theme is in the /app/design/frontend/default/default/template/queldorei folder but i don’t have customer/form folder
I edit the register.phtml and edit.phtml in the /app/design/frontend/base/default/template/customer/form folder but nothing happened.
Where you should edit these files?

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top