Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

Editing Nickname via Backend


Reply

4 Posts   1032 Views

Avatar
baba-papa

24 June 2009 at 4:15am Community Member, 279 Posts

I want to edit the members nicknames via the backend. By default only username, Email and password can be edited. My problem behind this: One of my members registered with a nickname that starts with an "$". When the templateparser processes a code where this nickname appears in, a fatal error occurs.

Thanks for your help.

Avatar
Hamish

24 June 2009 at 9:06am Community Member, 712 Posts

First of all, that is an interesting bug. Could you post the piece of the template that displays the nickname? There is no good reason why a name beginning with $ should fail.

Second of all, to do it without modifying any core files, you'll need to decorate the member object.

see: [url]http://doc.silverstripe.org/doku.php?id=dataobjectdecorator[/url]

Just read the Modifying CMS Fields section, this will show you how to augment an existing object so you can change the cms fields.

eg, in your member decorator:

public function updateCMSFields(FieldSet &$fields) {
$fields->push(new TextField('Nickname', 'Nickname'));
}

Avatar
baba-papa

24 June 2009 at 4:28pm Community Member, 279 Posts

Hello Hamish,

I get the following error message:

XML-Verarbeitungsfehler: nicht wohlgeformt
Adresse: http://musik-kaiserslautern.de/post/post
Zeile Nr. 84, Spalte 220:         <div id="ToID" class="field dropdown "><label class="left" for="Form_PostMessageForm_ToID">Empfänger wählen:</label><div class="middleColumn"><select id="Form_PostMessageForm_ToID" name="ToID"><option value="41">$M&M$</option><option value="21">$Marcel Cool$</option><option value="5">abdullah</option><option value="12">Anni :-)</option><option value="14">assassine</option><option value="29">Bärbel</option><option value="25">Cedi</option><option value="18">chidi</option><option value="24">Clarinette</option><option value="35">Das rebbhuhn</option><option value="26">esig</option><option value="40">Hanna Montana</option><option value="2">Hannes</option><option value="20">Jacobsisters</option><option value="13">janachen =)</option><option value="16">krisi</option><option value="15">larsi</option><option value="30">lenchen</option><option value="28">leni</option><option value="38">Lilli</option><option value="11">Love soccer :-P</option><option value="6">Lucky strike</option><option value="10">Marie :-)</option><option value="22">mausi</option><option value="9">melly </option><option value="1">Mister L</option><option value="34">mori</option><option value="27">Nessi</option><option value="31">PapaMT</option><option value="7">paul</option><option value="37">Pauli</option><option value="3">Räuber</option><option value="23">Renner</option><option value="19">Saibot</option><option value="8">skater@lex:)</option><option value="32">Test</option><option value="39">test1</option><option value="4">tester</option><option value="17">testerer</option><option value="36">The Devil</option><option value="33">vani</option></select></div></div>

Here is the template that displays the nickname:

<% _t('MESSAGES_TO', 'You can send messages to registered users.') %>
<p><a href="$Link"><% _t('INBOX', 'inbox') %></a></p>
$PostMessageForm

This is the method "PostMessageForm":

   function PostMessageForm() {
//Nicknames of all members is passed into an array
      $members = DataObject::get("Member", "", "Nickname");
      $allMembers = array();
      foreach($members as $member) {
         $allMembers[$member->ID] = "$member->Nickname";
      }
      $me = Member::currentUser();
      return new Form($this, "PostMessageForm", new FieldSet(
         new ReadonlyField("From", _t('PrivateMessagePage.FROM', 'From'), "$me->Nickname"),
         new DropdownField("ToID", _t('PrivateMessagePage.CHOOSERECEIVER', 'Choose receiver:'), $allMembers),
         new TextField("Subject", _t('PrivateMessagePage.SUBJECT', 'Subject')),
         new TextareaField("Body", _t('PrivateMessagePage.TEXT', 'Text'))

),
new FieldSet(
new FormAction("doPostMessage", _t('PrivateMessagePage.SUBMIT', 'submit'))
),
//Required fields are named inside the array. Without subject messages can´t be red.
new RequiredFields(array('Subject', 'Body'))
);
   }

Avatar
baba-papa

28 June 2009 at 2:53am Community Member, 279 Posts

I have a similar error again. A user registered with a nickname that has an "&". His profile throws an exeption, the template doesn´t render right.