VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: GJC Web Design on October 20, 2013, 21:02:29 PM

Title: Shopper fields 'required' not showing in forms (password, username etc)
Post by: GJC Web Design on October 20, 2013, 21:02:29 PM
Hi - have noticed with

2.0.24 that in the BT address form the required is missing for all the core fields except email (password, username etc)

tracked it down to  administrator/components/com_virtuemart/models/userfields.php ~ line 506

//Small ugly hack to make registering optional //do we still need that? YES !  notice by Max Milbers
if($register && $type == 'BT'  && VmConfig::get('oncheckout_show_register',1) ){

$corefields = $this->getCoreFields();
unset($corefields[2]); //the 2 is for the email field, it is necessary in almost anycase.
foreach($userFields as $field){
if(in_array($field->name,$corefields)){
$field->required = 0;
$field->value = '';
$field->default = '';

}
}


as I read this it sets all core field required to 0 therefore at the frontend e.g

Array
(
    [name] => password2
    [value] =>
    [title] => Confirm Password
    [type] => password
    [required] => 0
    [hidden] =>
    [formcode] =>

    [description] =>
)


if changed to

//Small ugly hack to make registering optional //do we still need that? YES !  notice by Max Milbers
if($register && $type == 'BT'  && VmConfig::get('oncheckout_show_register',1) ){

$corefields = $this->getCoreFields();
unset($corefields[2]); //the 2 is for the email field, it is necessary in almost anycase.
foreach($userFields as $field){
if(in_array($field->name,$corefields)){
$field->required = 1;
$field->value = '';
$field->default = '';

}
}


everything works as expected

Array
(
    [name] => password2
    [value] =>
    [title] => Confirm Password
    [type] => password
    [required] => 1
    [hidden] =>
    [formcode] =>

    [description] =>
)


Cheers

Title: Re: Shopper fields 'required' not showing in forms (password, username etc)
Post by: Jumbo! on October 20, 2013, 21:25:45 PM
Those fields are not required in VirtueMart account page because even guest users need to save their Bill To address who does not need to register. If you set these fields as required then guest checkout will not work in your site.
Title: Re: Shopper fields 'required' not showing in forms (password, username etc)
Post by: GJC Web Design on October 20, 2013, 22:56:08 PM
Ok - so not a bug - just an awful way of doing it..

then my answer is the same as in post   http://forum.virtuemart.net/index.php?topic=119722.0      :)

But there are loads of posts asking why the validation and validation styling is so - well - quirky..

Cheers
Title: Re: Shopper fields 'required' not showing in forms (password, username etc)
Post by: Milbo on October 23, 2013, 21:07:12 PM
Suggestions?
Title: Re: Shopper fields 'required' not showing in forms (password, username etc)
Post by: GJC Web Design on October 23, 2013, 21:09:20 PM
working on it...  :)

Gruß
Title: Re: Shopper fields 'required' not showing in forms (password, username etc)
Post by: GJC Web Design on October 25, 2013, 18:08:16 PM
This seems to work fine - gives correct validation on must register and no problems on the other two cases

administrator/components/com_virtuemart/models/userfields.php ~ line 506


//Small ugly hack to make registering optional //do we still need that? YES !  notice by Max Milbers
if($register && $type == 'BT'  && VmConfig::get('oncheckout_show_register',1) ){
$corefields = $this->getCoreFields();
unset($corefields[2]); //the 2 is for the email field, it is necessary in almost anycase.
if (!VmConfig::get ('oncheckout_only_registered', 0)) {
foreach($userFields as $field){
if(in_array($field->name,$corefields)){
$field->required = 0;
$field->value = '';
$field->default = '';
}
}
}
}


administrator/components/com_virtuemart/models/userfields.php ~ line 861


case 'password':
case 'password2':
$_return['fields'][$_fld->name]['formcode'] = '<input type="password" id="' . $_prefix.$_fld->name . '_field" name="' . $_prefix.$_fld->name .'" '.($_fld->required ? ' class="required"' : ''). ' size="30" class="inputbox" />'."\n";
break;




[attachment cleanup by admin]
Title: Re: Shopper fields 'required' not showing in forms (password, username etc)
Post by: creyl on July 16, 2014, 16:11:22 PM
Thanks!! Really helped me!!