Hey TheStone
just wanted to say thank you! I'm glad that you've checked the code and that it's ok
As far as the additional feature for the required and the optional fields is concerned, I have modified your code like this:
$COMPILE{profile} = <<'END_OF_SUB';
sub profile {
#------------------------------------------------------------------------
# Modify profile (custom)
#
my $self = shift;
my $user_tab = $self->{cfg}->{'user_table_use'};
my $db = $self->{sql}->table($user_tab);
my $cols = $db->cols;
my $req = {};
my $opt = {};
foreach my $c ( keys %$cols ) {
next if ( ! $self->{cgi}->{'req_'.$c} );
next if ( $c =~ /^(Username|Status|ReceiveMail|Newsletter|view_p|add_p|delete_p|modify_p|admin_p)/ );
$req->{$c} = $self->{cgi}->{"req_$c"};
}
$db->update($req, { 'Username' => $self->{user}->{Username} }) if ( $req );
foreach my $d ( keys %$cols ) {
next if ( $d =~ /^(Username|Status|ReceiveMail|Newsletter|view_p|add_p|delete_p|modify_p|admin_p)/ );
$opt->{$d} = $self->{cgi}->{"opt_$d"} if (defined $self->{cgi}->{"opt_$d"});
}
$db->update($opt, { 'Username' => $self->{user}->{Username} }) if ( $opt );
$self->auth_logging('profile change ') if ( $self->{cfg}->{log_file} );
return ('profile_form.html', {
msg => $self->_language('MSG_PROFILE_OK'),
header => $self->_language('HEA_HOME')
});
}
END_OF_SUB
It seems that this code does what I wanted:
- in the profile form, you can add "req_" or "opt_" in front of the fieldname (e.g. req_address, req_city, opt_handy)
- optional fileds can be deleted by just submitting a blank field (by deleting the content of the field)
- required fields can't be deleted... they can just be updated with another value
I'd be glad if you could check the above code for errors or if you have any other suggestions for optimization. I will try to create a plugin later and I'd like to have the code optimized first
Cheers,
Oliver
just wanted to say thank you! I'm glad that you've checked the code and that it's ok
As far as the additional feature for the required and the optional fields is concerned, I have modified your code like this:
Code:
$COMPILE{profile} = <<'END_OF_SUB';
sub profile {
#------------------------------------------------------------------------
# Modify profile (custom)
#
my $self = shift;
my $user_tab = $self->{cfg}->{'user_table_use'};
my $db = $self->{sql}->table($user_tab);
my $cols = $db->cols;
my $req = {};
my $opt = {};
foreach my $c ( keys %$cols ) {
next if ( ! $self->{cgi}->{'req_'.$c} );
next if ( $c =~ /^(Username|Status|ReceiveMail|Newsletter|view_p|add_p|delete_p|modify_p|admin_p)/ );
$req->{$c} = $self->{cgi}->{"req_$c"};
}
$db->update($req, { 'Username' => $self->{user}->{Username} }) if ( $req );
foreach my $d ( keys %$cols ) {
next if ( $d =~ /^(Username|Status|ReceiveMail|Newsletter|view_p|add_p|delete_p|modify_p|admin_p)/ );
$opt->{$d} = $self->{cgi}->{"opt_$d"} if (defined $self->{cgi}->{"opt_$d"});
}
$db->update($opt, { 'Username' => $self->{user}->{Username} }) if ( $opt );
$self->auth_logging('profile change ') if ( $self->{cfg}->{log_file} );
return ('profile_form.html', {
msg => $self->_language('MSG_PROFILE_OK'),
header => $self->_language('HEA_HOME')
});
}
END_OF_SUB
It seems that this code does what I wanted:
- in the profile form, you can add "req_" or "opt_" in front of the fieldname (e.g. req_address, req_city, opt_handy)
- optional fileds can be deleted by just submitting a blank field (by deleting the content of the field)
- required fields can't be deleted... they can just be updated with another value
I'd be glad if you could check the above code for errors or if you have any other suggestions for optimization. I will try to create a plugin later and I'd like to have the code optimized first
Cheers,
Oliver