Gossamer Forum
Home : Products : DBMan SQL : Discussion :

change the data of registration

Quote Reply
change the data of registration
Hello

how can user change the data of their registration?

The admin_fom is only for the Admin but often also the members would like to change their once delivered data.

Thanks
Quote Reply
Re: [hoefti] change the data of registration In reply to
Hi,

Sorry about the late reply.
In this case, you should add the script below into Home.pm:

Code:
$COMPILE{profile_form} = <<'END_OF_SUB';
sub profile_form {
my ($self, $msg) = @_;
return ('profile_form.html', { msg => $msg, header => 'Edit Profile' });
}
END_OF_SUB

$COMPILE{profile} = <<'END_OF_SUB';
sub profile {
my $self = shift;
my $user_tab = $self->{cfg}->{'user_table_use'};
my $db = $self->{sql}->table($user_tab);
my $cols = $db->cols;
my $info = {};
foreach my $c ( keys % $cols ) {
next if ( !$self->{cgi}->{"pro_$c"} );
next if ( $c =~ /^Username|Status|view_p|view_p|delete_p|modify_p|admin_p/ );
$info->{$c} = $self->{cgi}->{"pro_$c"};
}
$table->update($info, { Username => $self->{user}->{Username} }) if ( $info );
return home("Your profile was updated successfully!");
}
END_OF_SUB

Find the attached file and put it into the template set which you're using.

Now you can use it Laugh by the link: db.cgi?do=profile_form

Hope that helps,

TheStone.

B.

Last edited by:

TheStone: Aug 13, 2002, 4:38 PM
Quote Reply
Re: [TheStone] change the data of registration In reply to
Hi Stone,

first, I'd like to thank you for the contribution of this code Smile

I've tried to add it to my existing DBMan installation. After logging in and starting db.cgi&do=profile_form, everything is dispayed as it should (profile data is loaded into the form) and I can fill out the fields (e.g. overwrite wrong registration info).

But after submitting the new values with your form, it seems to hang somehow. The error_log keeps showing a "premature end of script" message and no data is being modified in the database. I have not uploaded the files in binary mode and there is no wrong path to perl in any script file. I have eaven made a fresh DBMan install to be able to test it again. But nothing seems to solve the problem. I never get a "Your profile was updated successfully!" reply Frown

I've added your code to Home.pm - there is only one small modification (marked in red):
next if ( $c =~ /^Username|Status|view_p|add_p|delete_p|modify_p|admin_p/ );

As far as your profile_form.html template is concerned, I've just added a submit button to it (otherwise, I wouldn't have been able to submit the form).

I'd be glad if you could take a look at this issue.

Thank you for your support
Oliver
Quote Reply
Re: [olivers] change the data of registration In reply to
If you can send me username and password to access the admin panel via email, I will have a closer look.

TheStone.

B.
Quote Reply
Re: [TheStone] change the data of registration In reply to
Hello again

thank you for your offer to have a closer look at the problem. Unfortunately, I have only installed the software on a test server that has no internet connection. I will put the new files on a production server once I have tested the mod.

In the meantime, I have done some debugging and logging and it seems that I have discovered the problem: the line beginning with $table->update(...) should start with $db->update(...).

Since I also want to have the profile changes logged, I've added another line of code.

Please check the code at the end of this message (I hope it's ok). I'm not a Perl-Guru Unsure

Thanks a lot your assistance.

Cheers,
Oliver

Code:
$COMPILE{profile_form} = <<'END_OF_SUB';
sub profile_form {
#------------------------------------------------------------------------
# Profile form
#
my($self,$msg) = @_;
return ('profile_form.html', {
msg => $self->_language('MSG_PROFILE'),
header => $self->_language('HEA_PROFILE')
});
}
END_OF_SUB


$COMPILE{profile} = <<'END_OF_SUB';
sub profile {
#------------------------------------------------------------------------
# Modify profile
#
my $self = shift;
my $user_tab = $self->{cfg}->{'user_table_use'};
my $db = $self->{sql}->table($user_tab);
my $cols = $db->cols;
my $info = {};
foreach my $c ( keys %$cols ) {
next if ( !$self->{cgi}->{'pro_'.$c} );
next if ( $c =~ /^(Username|Status|view_p|add_p|delete_p|modify_p|admin_p)/ );
$info->{$c} = $self->{cgi}->{'pro_'.$c};
}
$db->update($info, { 'Username' => $self->{user}->{Username} }) if ( $info );
$self->auth_logging('profile change ') if ( $self->{cfg}->{log_file} );
return ('home.html', {
msg => $self->_language('MSG_PROFILE_OK'),
header => $self->_language('HEA_HOME')
});

}
END_OF_SUB
Quote Reply
Re: [olivers] change the data of registration In reply to
Try add some debugging code at:

use Data::Dumper;
print $self->{in}->header;
print "<pre>".Dumper($info)."</pre>";
if ($info) {
$db->update($info, { 'Username' => $self->{user}->{Username} }) or die $GT::SQL::error;
}

Let me know what you get.

TheStone.


B.
Quote Reply
Re: [TheStone] change the data of registration In reply to
I have added your debugging code to the subroutine now.

Here is the output:

$VAR1 = {
'Email' => 'newmailaddress at newdomain dot com'
,
'Name' => 'Newfirstname Newlastname'
};


This corresponds to the new values that I have entered into the profile change form.

Is the output ok (I think it is Smile)?
Oliver
Quote Reply
Re: [TheStone] change the data of registration In reply to
Hi Stone

sorry to bother you again. There are additional fields in my user table (besides of Name and Email). Some of them are "required" and some are "optional". Occasionally, users want to delete optional fields for some reason. That's why I've tried to update an optional field (e.g. phone number) with a zero value in the profile change form. But the content of this field has not been deleted in the database.

I think it would be possible to slightly alter the profile sub and the profile template. There could be different field names in the template: "req_" for required, "opt_" for optional. All optional fields should be deleted if there is a zero value and all required fields couldn't be deleted (just updated).

It would be wonderful if you could help me out with the modification of the profile subroutine.

Thanks and all the best
Oliver

Last edited by:

olivers: Mar 6, 2004, 10:57 AM
Quote Reply
Re: [TheStone] change the data of registration In reply to
Hi Stone

I would appreciate it very much if you could check my debugging output. And I'm still looking for a solution concerning the required/optional fields.

Thank you and all the best
Oliver
Quote Reply
Re: [olivers] change the data of registration In reply to
I'm not quite sure about the problem. Sorry, there is nothing I can do to help you out without connection to your server. If you can install it on a testing server, I'll be happy to help you.

TheStone.

B.
Quote Reply
Re: [TheStone] change the data of registration In reply to
In the meantime, I have set up a temporary testing server with Internet connection. I will send you username and password to the admin panel via private message.

Thank you for helping me Smile
Oliver
Quote Reply
Re: [olivers] change the data of registration In reply to
Hey TheStone

just wanted to say thank you! I'm glad that you've checked the code and that it's ok Smile

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 Cool

Cheers,
Oliver
Quote Reply
Re: [olivers] change the data of registration In reply to
You don't have to do that, just simply deinfine all required column as NOT NULL and optional columns as NULL.

TheStone.


B.
Quote Reply
Re: [TheStone] change the data of registration In reply to
I've verified that all required columns are defined as not null and optional columns are defined as null. But it's weird: when I don't use my code changes as displayed above, I can overwrite the required fields with a zero value Unimpressed

Could you have a look at it in the Admin Panel?

Thanks
Oliver
Quote Reply
Re: [olivers] change the data of registration In reply to
TheStone has logged into my server and changed the subroutine above. He has provided a better solution to deal with my problem. Everything is working perfectly and error messages are now shown if a required field has been left empty. At this point, I'd like to say "thank you" again and make a compliment for GT's great customer service quality Cool !
Quote Reply
Re: [olivers] change the data of registration In reply to
I'm now trying to create a plugin for the user profile subs. Please have a look at the following thread:
http://www.gossamer-threads.com/...i?post=265122#265122
Quote Reply
Re: [olivers] change the data of registration In reply to
 
Ali
Quote Reply
Re: [megaline] change the data of registration In reply to
Hi,
I use the following code in my Home.pm, I used "profile_form.html" posted by STONE and I just added a submit button to the form. Now When I do "do=profile_form" I get my page an error message: Unknow tag Username....
Then I push the submit button after completing the form and I get: "Invalid Action" message.
Anyone could help to set this script to work correctly?

$COMPILE{profile_form} = <<'END_OF_SUB';
sub profile_form {
#------------------------------------------------------------------------
# Profile form
#
my($self,$msg) = @_;
return ('profile_form.html', {
msg => $self->_language('MSG_PROFILE'),
header => $self->_language('HEA_PROFILE')
});
}
END_OF_SUB

$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

Thank you
Ali
Ali
Quote Reply
Re: [megaline] change the data of registration In reply to
Hi Ali

you can download the UserProfile plugin. Have a look at this post:
http://www.gossamer-threads.com/...i?post=269244#269244

It has a help file and can be easily installed using DBManSQL's plugin manager.

Cheers,
Oliver