coldstone Global Moderator
     member is offline
![[avatar] [avatar]](http://xergs.doubtfulguest.net/images/avatar.png)
![[homepage] [homepage]](http://images.proboards.com/buttons/www_sm.gif) Joined: Aug 2006 Posts: 816 Karma: 18 |  | Javascript to Save a Commenter's Info « Thread Started on Apr 4, 2007, 10:42pm » | |
Problem: I would like a commenter's name, email, and homepage to be remembered after they comment and to automatically appear in the comment form fields.
Solution: GreyMatter comes with the javascript to do this, however, it isn't "hooked up" so to speak. A little template modifications and you are good to go.
First make sure that you have the cookie code variable ({{cookiescode}}) in your Entry Page Template templates (which the standard templates that ship with GM do).
Add these lines to your "{{entrycommentsform}} Posting Form" template:
Code:<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> <!--// document.newcomment.newcommentauthor.value = getCookie("gmcmtauth"); document.newcomment.newcommentemail.value = getCookie("gmcmtmail"); document.newcomment.newcommenthomepage.value = getCookie("gmcmthome"); document.newcomment.newcommentauthor.focus(); //--> </SCRIPT> <input name="bakecookie" type="checkbox" />Save Info?<br />
|
|
This goes nicely just in front of the 'Reset' button.
Lastly, modify your submit button to call the 'setGMcookies' javascript function. In your "{{entrycommentsform}} Posting Form" template change:
Code:| <input type="submit" value="Submit" class="button" /> |
|
to:
Code:| <input type="submit" value="Submit" class="button" onClick="javascript:setGMcookies()" /> |
|
Discussion: As features have been added, not all of them have been documented, particularly with the powerful template system that GreyMatter has. This recipe doesn't require any code modification, yet it is able to significantly enhance the user experience. If every template configuration were absorbed into the code, GreyMatter would quickly become unusable.
Note: If you have trouble getting the javascript to work, most browsers have an 'Error Console' that may give some feedback. Also, Firebug is an amazing Firefox plugin that can be very helpful.
| |
|
iamgundam New Member
 member is offline
Joined: May 2008 Posts: 1 Karma: 0 |  | Re: Javascript to Save a Commenter's Info « Reply #1 on May 18, 2008, 4:44am » | |
thank Q very much
| |
|
xiaojunznz2 New Member
 member is offline
Joined: May 2013 Gender: Male  Posts: 3 Karma: 0 |  | Re: Javascript to Save a Commenter's Info « Reply #2 Today at 5:10am » | |
You can surf the Internet access to relevant data and information, and discuss with friends, maybe can help you, wish you good luck.
__________________ I have a dream,it is a fantasy forever. buy diablo 3 Gold|RS Gold|Diablo 3 Gold|WOW Gold
| |
|