Programming in almost language

This is the site where you may share your knowledge and experience to eachother..

  • Categories

  • LinkedIn

  • Tweet Me

  • My footsteps

Plone MySQL Memberdata properties

Posted by Praveen Kumar on October 7, 2008

ello Everybody

How are you people..

offf… now finally i have solved my problem. ok let me once again introduce my problem.

No not a problem we may say our requirement..

My requirement was the one could register with my site by clicking on join link which will take to join_form(default form plone site) and once he/she registered they could enter their profile personalize_form(default form plone site) and if that user come back to his/her profile for editing then all the value which they entered should display on the personalize_form.


STEP 1 – > initially we had two table registration and profile

table structure

registration((

`userreg` varchar(40) character set utf8 default NULL,

`password` varchar(120) character set utf8 default NULL,

KEY `HANDLE` (`HANDLE`))


profile(

`userreg` varchar(40) default NULL,

`FIRSTNAME` varchar(50) default NULL,

`LASTNAME` varchar(40) default NULL,

`SEX` varchar(1) default NULL,

`DOB` date default NULL,

`ADDRESS` varchar(200) default NULL,

`MOBILE` varchar(20) default NULL,

`security_question` varchar(50) default NULL,

`security_answer` varchar(50) default NULL,

`email` varchar(100) default NULL,

KEY `Index_1` (`userreg`)

)

and i need to store the records in both of the table which i was not able even i tried to mapped and also tried to write a view but could not manage, as we know we can not insert the record in view.

STEP 2- > so finally i decided to merged all the fields in to single table very funny

and removed all the duplicate fields(if matches).

In source_properties i mapped the corresponding field with

users_table=registration,

users_col_username=HANDLE and

users_col_password=password and checked the checkbox

Only return properties when there is a match and save changes.


NOTE : i did not write anything col_mapping text area of source_properties to match fields.


and i customized personalize_form and add some more fields like mobile,phone,city,country,university…etc.


now if i click on save button all the field should be saved to table’s field correspondingly.

for that we have to keep in mind, the form’s field name and table’s field name must be same then no need to map in col_mapping text area,

but if form’s field is different from table’s field then we have to map(e_mail/email in the form of form field/table field). so to get rid of this issue i created the fields in table with the same name of form’s field.

so now i am able to save the value into table.

Now the question arises here how to appear the same value on form if i come back after some days or visited again the personalize_form

so first i tried to add field in portal_memberdata properties sheet

for appearing the value on form i write the code for every field see how i did

————————————————————————————————————-

<html xmlns=”http://www.w3.org/1999/xhtml&#8221; xml:lang=”en”
lang=”en”
metal:use-macro=”here/prefs_main_template/macros/master”
i18n:domain=”plone”>

<head>
<metal:block fill-slot=”top_slot”
tal:define=”dummy python:request.set(‘disable_border’,1)” />

<metal:calendar fill-slot=”javascript_head_slot”>
<!– ECMAScript calendar –>
<style type=”text/css” media=”all”
tal:content=”string:@import url($portal_url/jscalendar/calendar-system.css);”></style>
<script type=”text/javascript”
tal:attributes=”src string:$portal_url/jscalendar/calendar_stripped.js”></script>
<script type=”text/javascript” charset=”iso-8859-1″
tal:condition=”exists: portal/jscalendar/calendar-en.js”
tal:attributes=”src string:$portal_url/jscalendar/calendar-en.js”></script>
</metal:calendar>

<script language=”JavaScript” src=”validation.js” type=”text/javascript”></script>

</head>
<body>                                                                               <!– TO DO VALIDATION JUST ADD validate_personalize PRECEEDING COMA
OF THIS FORM VALIDATION TAB NEXT TO EDIT AND TEXT AND MAKE SURE
YOU HAVE validate_personalize PYTHON SCRIPT FILE–>

<div metal:fill-slot=”prefs_configlet_content”
tal:define=”errors options/state/getErrors;”>

<span tal:define=”dummy python:request.response.setHeader(‘pragma’,’no-cache’)” />

<div id=”content”
class=”documentEditable”>

<h5 class=”hiddenStructure”>Views</h5>

<ul class=”contentViews”>
<li>
<a href=””
tal:attributes=”href string: ${portal_url}/author/${member}”
i18n:translate=”label_view”>View</a>
</li>
<li class=”selected”>
<a href=””
tal:attributes=”href string:${portal_url}/profile”
i18n:translate=”label_edit”>Edit</a>
</li>
</ul>

<div class=”contentActions”>
&nbsp;
</div>

<div class=”documentContent” id=”region-content”>

<a name=”documentContent”></a>

<div metal:use-macro=”here/global_statusmessage/macros/portal_message”>
Portal status message
</div>

<h1 i18n:translate=”heading_my_preferences”>Personal Preferences</h1>

<a href=””
class=”link-parent”
tal:attributes=”href string: $portal_url/plone_memberprefs_panel”
i18n:translate=”label_up_to_preferences”>
Up to My Preferences
</a>

<p i18n:translate=”description_my_preferences”>
Your personal settings.
</p>

<form action=”personalize” name=”profile”
method=”post”
enctype=”multipart/form-data”
class=”enableUnloadProtection”
tal:condition=”member”
tal:attributes=”action template_id”>

<fieldset tal:define=”macros here/additional_memberdata/macros | nothing;
top_macro macros/top | nothing;
showTop python:top_macro;
bottom_macro macros/bottom | nothing;
showBottom python:bottom_macro;
after_primary macros/after_primary| nothing;
showAfterPrimary python:after_primary;”>

<legend i18n:translate=”legend_personal_details”>Personal Details</legend>

<tal:macro condition=”showTop”>
<div metal:use-macro=”top_macro”/>
</tal:macro>

<!–                          Full name                      –>

<div class=”field”
tal:define=”error errors/fullname | nothing;
fullname python:request.get(‘fullname’, member.getProperty(‘fullname’, ”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”fullname” i18n:translate=”label_full_name”>First Name</label>
<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)</span>
<div tal:content=”error”>Validation error output</div>

<input type=”text”
id=”fullname”
name=”fullname”
size=”25″
tabindex=””
onfocus=”formtooltip(‘subscribe_help’,1)”
value=”member.fullname html_quote”
tal:attributes=”value fullname;
tabindex tabindex/next;
disabled python:member.canWriteProperty(‘fullname’) and default or ‘disabled'”

/>
</div>
<!–          Last name     —>

<div class=”row”
tal:define=”error errors/lastname| nothing;
lastname python:request.get(‘lastname’, member.getProperty(‘lastname’, ”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”lastname”
i18n:translate=”label_last_name”>Last Name</label>

<div class=”formHelp” i18n:translate=”help_last_name_creation”>
Enter last name, eg.Smith.
</div>

<div tal:content=”error”>Validation error output</div>

<input type=”text”
name=”lastname”
id=”lastname”
size=”30″
tabindex=””
onfocus=”formtooltip(‘subscribe_help’,1)”
value=”member.lastname html_quote”
tal:attributes=”value lastname;
tabindex tabindex/next;
disabled python:member.canWriteProperty(‘lastname’) and default or ‘disabled'”
/>

</div>

<!– starts –>
<div class=”field”
tal:define=”sex python:request.get(‘sex’, member.getProperty(‘sex’));
tabindex tabindex/next;”>
<input type=”radio”
class=”noborder”
name=”sex”
value=”m”
id=”cb_m”
tabindex=””
onfocus=”formtooltip(‘sex_help’,1)”
onblur=”formtooltip(‘sex_help’,0)”
tal:attributes=”checked python:test(‘m’ in sex, ‘checked’, ”);”
/>Male<br>
<input type=”radio”
class=”noborder”
name=”sex”
value=”f”
id=”cb_f”
tabindex=””
onfocus=”formtooltip(‘sex_help’,1)”
onblur=”formtooltip(‘sex_help’,0)”
tal:attributes=”checked python:test(‘f’ in sex, ‘checked’, ”);”
/>Female

</div>

<!– end –>
<!–          DOB(mm/dd/yy)     —>

<!– start   –>
<div class=”row”
tal:define=”error errors/dob| nothing;
dob python:request.get(‘dob’, member.getProperty(‘dob’, ”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)
</span>
<div tal:content=”error”>Validation error output</div>
<tal:block tal:define=”here_start here/dob|nothing;
dob python:request.get(‘dob’, member.getProperty(‘dob’,”));
formname string:profile;
firstDay dob/firstDay|nothing;
inputname string:dob;
show_hm python:0;
inputvalue python:test(dob, dob, ”);
tabindex tabindex/next;” >
<tal:block metal:use-macro=”here/calendar_macros/macros/calendarDatePickerBox|here/calendar_slot/macros/calendarDatePickerBox” />
</tal:block>
<select name=”dob_month”
id=”profile_dob_0_month”
tal:attributes=”onfocus onfocus|nothing;
onblur onblur|nothing;
onchange string:update_date_field(‘profile_dob_0′,’profile_dob_0_year’,’profile_dob_0_month’,’profile_dob_0_day’);”>
<option value=”1968″
tal:attributes=”value python:’1987′;”>
</option>
</select>
</div>

<!– end –>
<tal:con tal:content=”python:request.get(‘dob’, member.getProperty(‘dob’, ”))” />

<!–          Address     —>

<div class=”field”
tal:define=”error errors/address | nothing;
address python:request.get(‘address’, member.getProperty(‘address’, ”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”address”
i18n:translate=”label_address”>Address</label>
<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)</span>
<div tal:content=”error”>Validation error output</div>

<input type=”text”
name=”address”
id=”address”
size=”30″
tabindex=””
value=”member.address html_quote”
tal:attributes=”value address;
tabindex tabindex/next;
disabled python:member.canWriteProperty(‘address’) and default or ‘disabled'” />

</div>

<!–          Country     —>

<div class=”row”
tal:define=”error errors/country | nothing;
country python:request.get(‘country’, member.getProperty(‘country’, ”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”country”
i18n:translate=”label_country”>Country</label>
<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)</span>
<div class=”formHelp” i18n:translate=”help_phone_creation”>
Special characters are not allowed
</div>
<div tal:content=”error”>Validation error output</div>

<input type=”text”
name=”country”
id=”country”
size=”30″
value=”member.country html_quote”
tal:attributes=”value country;
tabindex tabindex/next;
disabled python:member.canWriteProperty(‘country’) and default or ‘disabled'” />

</div>

<!–          Pin Code     —>

<div class=”row”
tal:define=”error errors/pincode | nothing;
pincode python:request.get(‘pincode’, member.getProperty(‘pincode’, ”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”pincode”
i18n:translate=”label_mobile”>Pincode</label>
<div class=”formHelp” i18n:translate=”help_pincode_creation”>
Enter only numeric value
</div>

<div tal:content=”error”>Validation error output</div>

<input type=”text”
name=”pincode”
id=”pincode”
size=”30″
value=”member.pincode html_quote”
tal:attributes=”value pincode;
tabindex tabindex/next;
disabled python:member.canWriteProperty(‘pincode’) and default or ‘disabled'” />

</div>

<!–          Mobile     —>

<div class=”row”
tal:define=”error errors/mobile | nothing;
mobile python:request.get(‘mobile’, member.getProperty(‘mobile’, ”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”mobile”
i18n:translate=”label_mobile”>Mobile</label>
<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)</span>
<div class=”formHelp” i18n:translate=”help_mobile_creation”>
Enter only numeric value
</div>

<div tal:content=”error”>Validation error output</div>

<input type=”text”
name=”mobile”
id=”mobile”
size=”30″
value=”member.mobile html_quote”
tal:attributes=”value mobile;
tabindex tabindex/next;
disabled python:member.canWriteProperty(‘mobile’) and default or ‘disabled'” />

</div>

<!–                          Email                      –>

<div class=”field”
tal:define=”error errors/email | nothing;
email python:request.get(’email’, member.getProperty(’email’,”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”email” i18n:translate=”label_email”>E-mail</label>

<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)</span>

<div tal:content=”error”>Validation error output</div>

<input type=”text”
id=”email”
name=”email”
size=”25″
tabindex=””
value=”member.email html_quote”
onfocus=”formtooltip(‘new_email_help’,1)”
tal:attributes=”value email;
tabindex tabindex/next;
readonly python:member.canWriteProperty(’email’) and default or ‘readonly'”

/>
</div>

<!–                          Question                      –>

<div class=”field”
tal:define=”error errors/question | nothing;
question python:request.get(‘question’, member.getProperty(‘question’,”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”question” i18n:translate=”label_question”>Question</label>

<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)</span>

<div tal:content=”error”>Validation error output</div>

<select name=”question”
id=”question”
tabindex=””
tal:attributes=”tabindex tabindex/next;
disabled python:member.canWriteProperty(‘question’) and default or ‘disabled'”>

<tal:block tal:define=”bank python:[‘What was the name of your first school?’,’Where did you meet your spouse?’,’Who was your childhood hero?’,’What is your favourite past time?’]”
tal:repeat=”ques bank”>
<option value=”None”
tal:content=”python:ques”
tal:attributes=”value python:ques;
selected python:test(question==ques, ‘selected’, None);”>
</option>

</tal:block>
</select>
</div>

<!–                          Answer                      –>

<div class=”field”
tal:define=”error errors/answer | nothing;
answer python:request.get(‘answer’, member.getProperty(‘answer’,”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>

<label for=”answer” i18n:translate=”label_answer”>Answer</label>

<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)</span>

<div tal:content=”error”>Validation error output</div>

<input type=”password”
id=”answer”
name=”answer”
size=”30″
tabindex=””
value=”member.answer html_quote”
tal:attributes=”value answer;
tabindex tabindex/next;
readonly python:member.canWriteProperty(‘answer’) and default or ‘readonly'”
/>

</div>
<!– hence –>

<!–div class=”field”
tal:define=”error errors/dob | nothing;
dob python:request.get(‘dob’, member.getProperty(‘dob’,”));”
tal:attributes=”class python:test(error, ‘field error’, ‘field’)”>
<label for=”question” i18n:translate=”label_dob”>Date of birth</label>
<span class=”fieldRequired” title=”Required”
i18n:attributes=”title title_required;”
i18n:translate=”label_required”>(Required)</span>
<div tal:content=”error”>Validation error output</div>
<select name=”dob”
id=”dob”
tabindex=””
tal:attributes=”tabindex tabindex/next;
disabled python:member.canWriteProperty(‘dob’) and default or ‘disabled'”>
<tal:block tal:define=”bank python:[‘2000′,’2001′,’2002′,’2003’]”
tal:repeat=”ques bank”>
<option value=”None”
tal:content=”python:ques”
tal:attributes=”value python:ques;
selected python:test(dob==ques, ‘selected’, None);”>
</option>
</tal:block>
</select>
</div–>

<!–input type=”hidden” name=”dob”
id=”join_form_dob_0″>
<select name=”dob_year”
id=”join_form_dob_0_year;
onfocus onfocus|nothing;
onblur onblur|nothing;
onchange string:plone.jscalendar.update_date_field(‘join_form_dob_0′,’join_form_dob_0_year’,’join_form_dob_0_month’);”>
onblur onblur|nothing;”>
<option value=”1968″
tal:attributes=”value python:’1987′;”>
</option>
</select>
<!–select tal:attributes=”name string:${inputname}_month;
id string:${input_id}_month;
onfocus onfocus|nothing;
onblur onblur|nothing;
onchange string:plone.jscalendar.update_hidden(‘#${input_id}’);”>
onblur onblur|nothing;”>
<option value=”subj”
tal:repeat=”month months”
tal:attributes=”value month/value; selected month/selected”>
</option>
</select–>
<!– end –>

<div class=”field”
tal:condition=”site_properties/visible_ids|nothing”
tal:define=”visible_ids python:request.get(‘visible_ids’, member.getProperty(‘visible_ids’,”));”>

<input type=”checkbox”
class=”noborder”
name=”visible_ids”
id=”cb_invisible_ids”
tal:attributes=”tabindex tabindex/next;
checked python:test(visible_ids, ‘checked’, None);
disabled python:member.canWriteProperty(‘visible_ids’) and default or ‘disabled'”
/>

<label for=”cb_invisible_ids”
i18n:translate=”label_edit_short_names”>Allow editing of Short Names</label>

<div class=”formHelp” i18n:translate=”help_display_names”>
Determines if Short Names (also known as IDs) are
changable when editing items. If Short Names
are not displayed, they will be generated automatically.
</div>

</div>

<div class=”field”
tal:condition=”here/portal_skins/allow_any”
tal:define=”skinvar python:request.get(here.portal_skins.getRequestVarname(), ”);
skindefault here/portal_skins/getDefaultSkin;
skincurrent python:test(skinvar, skinvar, skindefault);”>

<label for=”portal_skin” i18n:translate=”label_look”>Look</label>

<div i18n:translate=”help_look”
class=”formHelp”>
Appearance of the site.
</div>

<select name=”portal_skin”
id=”portal_skin”
tabindex=””
tal:attributes=”tabindex tabindex/next;
disabled python:member.canWriteProperty(‘portal_skin’) and default or ‘disabled'”
>
<option value=”#”
i18n:translate=””
tal:repeat=”skin container/portal_skins/getSkinSelections”
tal:attributes=”value skin;
selected python:test(skincurrent==skin, ‘selected’, None);”
tal:content=”skin”
>dummy skin</option>
</select>
</div>

<div class=”field”
tal:define=”portrait mtool/getPersonalPortrait;”>

<label for=”portrait” i18n:translate=”label_portrait”>Portrait</label>

<img src=”” alt=””
height=”100″
width=”75″
class=”portraitPhoto”
style=”float: right;”
tal:condition=”portrait”
tal:attributes=”src portrait/absolute_url”
/>

<div class=”formHelp” i18n:translate=”help_portrait”>
To add or change the portrait: click the “Browse” button;
select a picture of yourself. Recommended image size is 75
pixels wide by 100 pixels tall.
</div>

<input type=”file”
name=”portrait”
id=”portrait”
size=”20″
tabindex=””
tal:attributes=”tabindex tabindex/next;”
/>

<br />

<input class=”noborder”
tabindex=””
type=”checkbox”
id=”pdelete”
value=”Delete Portrait”
name=”delete_portrait”
tal:attributes=”tabindex tabindex/next;”
/>
<label for=”pdelete” i18n:translate=”label_delete_portrait”>Delete Portrait</label>

</div>

<tal:macro condition=”showBottom”>
<div metal:use-macro=”bottom_macro” />
</tal:macro>

<div class=”formControls”>
<input class=”context”
tabindex=””
type=”submit”
value=”Save”
name=”form.button.Save”
i18n:attributes=”value label_save;”
tal:attributes=”tabindex tabindex/next;” onclick=”profileFormValid()”
/>
<input class=”standalone”
tabindex=””
type=”submit”
value=”Cancel”
name=”form.button.Cancel”
i18n:attributes=”value label_cancel;”
tal:attributes=”tabindex tabindex/next;”
/>
</div>

</fieldset>
<input type=”hidden” name=”form.submitted” value=”1″/>
</form>
<script language=”JavaScript” type=”text/javascript”>
function profileFormValid(){

//You should create the validator only after the definition of the HTML form

var frmvalidator  = new Validator(“profile”);

frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation(“fullname”,”req”,”Please enter your First Name”);
frmvalidator.addValidation(“fullname”,”maxlen=20″,”Max length for FirstName is 20″);

}
</script>

</div>

</div>

</div>

</body>
</html>

————————————————————————————————————-

but again an issue arise

if i change the value of any field from backend(i mean from database directly) then the changed value was not appearing on the personalize_form for eg, if i enetred city=Newyork

then in database its saving the Newyork value and form itself it showing me ‘Newyork’ i was happy

but what will happen if i change from database city=’USA’ 😦 because i should get the value from database as we already had some existing records that also has to be imported,

then i did not do anything i removed all the value which i added from portal_memberdata which i added but keep two field as it is in memberdata that is fullname and email.


now if i change any value from back end it is dislplaying with changed value, really i am so happy now.

now think–


now i am thinking if i remove some code (see attached file) like member.getProperty and canWriteProperty then the value will be remain on form..

i treid that too but that was not working so i did not make any changes on personalize_form what you think?

Please leave any suggestion or comments on this post..

i am ready to hear criticism too.


Thank you

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: