Skip to main content
added 7 characters in body; edited tags
Source Link
Piyush
  • 5.9k
  • 9
  • 34
  • 66

I'm trying to customize the form for customer account creation and I would like to use the same form for different types of customers, i.e. private and companies. What I want to achieve is using the same form for both and show different fields according to the choice of the user: if user choose 'private' he has to fill in some fields, if he chooses 'company', additional fields - for the address and VAT - are shown.

So i'veI've enabled address fields in the local.xmllocal.xml and they're correctly shown or hidden, depending on which button (private or company) is chosen.

The problem is that if I simply hide the address fields, form is validated also on those fields, unless I put a

$this->setShowAddressFields(false);

just before the

if($this->getShowAddressFields()): ?

to hide address fields and suppress validation. I've also put <input type="hidden" name="create_address" value="0" /> to

<input type="hidden" name="create_address" value="0" />

to skip addresss fields validation.

So I've tried with jquery to change the setShowAddressFields whenever the user click the button to choose its type, something like

        $('#choose-type button').click(function(){
            if($(this).val() == 'private'){
                $(this).addClass('selected');
                $('#choose-type button').last().removeClass('selected');
                $('.required-company').removeClass('visible'); 
                <?php $addrEnabled = $this->setShowAddressFields(false) ?>
                
            }else{
                $(this).addClass('selected');
                $('#choose-type button').first().removeClass('selected');
                <?php $addrEnabled = $this->setShowAddressFields(true) ?>
                $('.required-company').addClass('visible');
            }
        });

I've also tried to show two different forms, in the same template, one with $this->setShowAddressFields(false)$this->setShowAddressFields(false) and the other with $this->setShowAddressFields(true)$this->setShowAddressFields(true) and show/hide the right form, and validate with Varien the right form, like this

var dataForm = new VarienForm('form-validate', true);
var dataFormbis = new VarienForm('form-validate-bis', true);

but still no luck.

So it is possible to achieve something like this in the same template, or I have to forcedly create two different templates?

I'm trying to customize the form for customer account creation and I would like to use the same form for different types of customers, i.e. private and companies. What I want to achieve is using the same form for both and show different fields according to the choice of the user: if user choose 'private' he has to fill in some fields, if he chooses 'company', additional fields - for the address and VAT - are shown.

So i've enabled address fields in the local.xml and they're correctly shown or hidden, depending on which button (private or company) is chosen.

The problem is that if I simply hide the address fields, form is validated also on those fields, unless I put a

$this->setShowAddressFields(false);

just before the

if($this->getShowAddressFields()): ?

to hide address fields and suppress validation. I've also put <input type="hidden" name="create_address" value="0" /> to skip addresss fields validation.

So I've tried with jquery to change the setShowAddressFields whenever the user click the button to choose its type, something like

        $('#choose-type button').click(function(){
            if($(this).val() == 'private'){
                $(this).addClass('selected');
                $('#choose-type button').last().removeClass('selected');
                $('.required-company').removeClass('visible'); 
                <?php $addrEnabled = $this->setShowAddressFields(false) ?>
                
            }else{
                $(this).addClass('selected');
                $('#choose-type button').first().removeClass('selected');
                <?php $addrEnabled = $this->setShowAddressFields(true) ?>
                $('.required-company').addClass('visible');
            }
        });

I've also tried to show two different forms, in the same template, one with $this->setShowAddressFields(false) and the other with $this->setShowAddressFields(true) and show/hide the right form, and validate with Varien the right form, like this

var dataForm = new VarienForm('form-validate', true);
var dataFormbis = new VarienForm('form-validate-bis', true);

but still no luck.

So it is possible to achieve something like this in the same template, or I have to forcedly create two different templates?

I'm trying to customize the form for customer account creation and I would like to use the same form for different types of customers, i.e. private and companies. What I want to achieve is using the same form for both and show different fields according to the choice of the user: if user choose 'private' he has to fill in some fields, if he chooses 'company', additional fields - for the address and VAT - are shown.

So I've enabled address fields in the local.xml and they're correctly shown or hidden, depending on which button (private or company) is chosen.

The problem is that if I simply hide the address fields, form is validated also on those fields, unless I put a

$this->setShowAddressFields(false);

just before the

if($this->getShowAddressFields()): ?

to hide address fields and suppress validation. I've also put

<input type="hidden" name="create_address" value="0" />

to skip addresss fields validation.

So I've tried with jquery to change the setShowAddressFields whenever the user click the button to choose its type, something like

        $('#choose-type button').click(function(){
            if($(this).val() == 'private'){
                $(this).addClass('selected');
                $('#choose-type button').last().removeClass('selected');
                $('.required-company').removeClass('visible'); 
                <?php $addrEnabled = $this->setShowAddressFields(false) ?>
                
            }else{
                $(this).addClass('selected');
                $('#choose-type button').first().removeClass('selected');
                <?php $addrEnabled = $this->setShowAddressFields(true) ?>
                $('.required-company').addClass('visible');
            }
        });

I've also tried to show two different forms, in the same template, one with $this->setShowAddressFields(false) and the other with $this->setShowAddressFields(true) and show/hide the right form, and validate with Varien the right form, like this

var dataForm = new VarienForm('form-validate', true);
var dataFormbis = new VarienForm('form-validate-bis', true);

but still no luck.

So it is possible to achieve something like this in the same template, or I have to forcedly create two different templates?

Source Link
sissy
  • 534
  • 1
  • 8
  • 24

Magento show Address fields and validate registration form only under some conditions

I'm trying to customize the form for customer account creation and I would like to use the same form for different types of customers, i.e. private and companies. What I want to achieve is using the same form for both and show different fields according to the choice of the user: if user choose 'private' he has to fill in some fields, if he chooses 'company', additional fields - for the address and VAT - are shown.

So i've enabled address fields in the local.xml and they're correctly shown or hidden, depending on which button (private or company) is chosen.

The problem is that if I simply hide the address fields, form is validated also on those fields, unless I put a

$this->setShowAddressFields(false);

just before the

if($this->getShowAddressFields()): ?

to hide address fields and suppress validation. I've also put <input type="hidden" name="create_address" value="0" /> to skip addresss fields validation.

So I've tried with jquery to change the setShowAddressFields whenever the user click the button to choose its type, something like

        $('#choose-type button').click(function(){
            if($(this).val() == 'private'){
                $(this).addClass('selected');
                $('#choose-type button').last().removeClass('selected');
                $('.required-company').removeClass('visible'); 
                <?php $addrEnabled = $this->setShowAddressFields(false) ?>
                
            }else{
                $(this).addClass('selected');
                $('#choose-type button').first().removeClass('selected');
                <?php $addrEnabled = $this->setShowAddressFields(true) ?>
                $('.required-company').addClass('visible');
            }
        });

I've also tried to show two different forms, in the same template, one with $this->setShowAddressFields(false) and the other with $this->setShowAddressFields(true) and show/hide the right form, and validate with Varien the right form, like this

var dataForm = new VarienForm('form-validate', true);
var dataFormbis = new VarienForm('form-validate-bis', true);

but still no luck.

So it is possible to achieve something like this in the same template, or I have to forcedly create two different templates?