plainblack.com
Username Password
search
Bookmark and Share

Update Profile v.0.1

Synopsis 

^updateProfile( [url], [message] );

url

If this part of the profile is updated successfully, redirect to this url.

For example: http://www.mycompany.nl/my-profile/my-work#mywork 

 

message

If the part of the profile is updated successfully, display this message while waiting for redirect.

For example:

"Your profile will be updated. You will redirect to your profile page." 

 

What can this macro do and what can't it do?

With this macro you can let your registered users change their profile in parts. For example, you can show their profile on one page, make buttons to change the work part or the part with personal information, or just their photo and/or avatar.

It will ask for required fields, inform you about duplicate email adresses, but only if you post an input field named 'email' or for other fields that you actually post. It will inform the user of errors or success and can redirect the user to another location on success.

 

How to use

Create a static form - this macro can't create the form for you yet. In this form you put input boxes for all the profile fields you'd like to edit. Use the fieldname that is displayed in Admin Console -> User Profiling as the name for your input box. If you like to display the current information, use the user-macro to retrieve it. Above the form you put the macro. This is the place where errormessages will be displayed. You will post this form to this same page. 

For example:

<h2>edit you email here</h2> 

<p class="error">^updateProfile(/my-profile,"Smile, you're on candid camera.");</p>

<form action="/^Page(url)" method="post"> 

<input name="email" value="^User(email);" type="text" /></form>

 

How to use with files and images

If you update files and images you should put three input tags in your form,

  1. one hidden with the name of the field or image and the current value of the field, (use ^User(); to get it)
  2. one file-type with the name of the field with "_file" appended to it and
  3. one with "__" prepended and "_action" appended to it, with the value "upload".

Only if the user selects a new file, the image or file will be changed. In any other case, the current image or file will be kept. In all cases, the "lastRenewed" value of the account in the database will be updated. You do not have to use 'delete' or 'keep' input-boxes or first delete the current and then upload a new file.

For example:

<input type="hidden" name="avatar" value="^User(avatar);" /> 

<input type="hidden" name="_avatar_action" value="upload" />

<input type="file" name="avatar_file" value="" /> 

Off course it would be nice to display the image, preferably the thumbnail, if it's there.  But that's another macro.

 

Tips

If you use this macro to update files and images, don't forget to put enctype="multipart/form-data" in your form, or the message "File not received. Image too big?" will keep appearing. 

It's very handy to add an anchor in the form-action, so you will scroll to the point in the page where your message on success, or the errormessages, will appear. 

<a name="theplacetochangeyouremailadress"></a> 

<form action="/^Page(url);#theplacetochangeyouremailadress method="post" enctype="multipart/form-data" >

Of course you can also do this in the url in the macro itself.

 

Advanced use

You cannot use the ^User(); macro on checkboxes and radio fields where CHECKED or checked=checked has to appear. You can use the SQL macro to enter checked=checked in one of the radio input fields or CHECKED behind your checkbox like so:

<input type="radio" id="geslachtvrouw" name="gender" value="female" ^SQL("select (SELECT CASE WHEN fieldData = 'female' THEN 'checked=checked' ELSE '' END) as outCome from userProfileData where userId='^#;' and fieldName='gender'",^0;); />


Status of this macro/Questions (for those who know more about WebGUI than I)

This is a working macro, however it will not win a beauti contest. You could call it beta, but it's not that it doesn't work, it's just not elegant. I would like to know how I could have done this in a better way than I have now. There's a lot of comment in this macro on why I did what I did. 

One of the things in WebGUI that would have made it easier to program this macro more elegantly is the ability to (optionally) pass sub validateData a variable so it only updates the values that are passed to it. Now it forces you to update all editable fields and thats why I had to make my_validateData. Is this the way to go?

Another thing is the private fields that are used for uploading files. I have found where I can check for their existence, but even after hours of searching, I haven't found where these input fields are parsed. (That means: where is _file actually stripped off?) 

 

Kind regards,

Arjan Widlak

Visit our website:
http://www.unitedknowledge.nl

Recent projects:
http://www.samenwerkenaannederland.nl
http://participatie.vrom.nl
http://www.platformoverstromingen.nl
http://toekomstglb.unitedknowledge.nl

We are looking for:
PERL Programmers
Linux/Debian Sysops

United Knowledge

Keizersgracht 74
1015 CT Amsterdam
T +31 (0)20 52 18 300
F +31 (0)20 52 18 301
http://www.unitedknowledge.nl 

System RequirementsPlease be advised: this contribution was tested with something older than WebGUI 7.5. When this contribution was uploaded there was no field for the author to fill out regarding it's requirements.
Comments
DownloadupdateProfile.pm updateProfile.pm
LinksNo Support Offered
Statistics Downloads: 496
Views: 2610
Rating: 0
Updated: 5/6/2008
Keywords macros
NavigationBack to the Bazaar
© 2018 Plain Black Corporation | All Rights Reserved