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.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

How to add form fields to admin?


Reply


5 Posts   2902 Views

Avatar
Decisive Flow

Community Member, 73 Posts

15 November 2006 at 2:52pm

I've managed to add a signup form, which is connected to a newsletter. However int he admin section of SS, the fields "first name" and "surname" are still there and my new fields "Company" and "country" aren't.

I've checked out http://doc.silverstripe.com/doku.php?id=forms&s=form but it doesn't seem to answer this question...

Avatar
Decisive Flow

Community Member, 73 Posts

16 November 2006 at 2:10pm

Any news on this one? it's kind of major because we want to store a little more info on the beta testers for PlanHQ and at the moment we're missing it all...

Avatar
Simon

Core Development Team, 27 Posts

16 November 2006 at 5:07pm

Ok, the standard member does'nt have any of the extra fields on it, so the form handler doesn't save the fields you've got in the form.

You'll need to do these things.
¤ Create a new Member class,
¤ Add the fields "Company" and "Country" to the member,
¤ Replace the getCMSfields on the member, to reference the new fields.
¤ Change the form to create and save into the new member.
¤ Finally add the code below to change the default member class in _config to use your special new class..

Object::useCustomClass( 'Member', 'newMemberClass' );

Avatar
Decisive Flow

Community Member, 73 Posts

17 November 2006 at 1:45pm

ummmm... Mark and I are trying to speak your language, but failing... here is my code based on your forum reply and the member page I found in the documentation - i dont think i am getting an error, but i am also not getting any fields in the font end :) - I have also added: Object::useCustomClass( 'Member', 'BetaTesterForm' ); to the _config file

code:

class BetaTesterForm extends Member {
   static $db = array(
      "Company" => "Text",
      "Country" => "Text",
   );
function getCMSFields() {
   $fields = parent::getCMSFields();
   $fields->insertBefore(new TextField("Company"), "Text");
   $fields->insertBefore(new TextField("Country"), "Text");
   $fields->removeByName("Firstname");
   $fields->removeByName("Surname");
   return $fields;
}
function BetaTesterForm() {

return new Form($this, "BetaTesterForm", new FieldSet(
// List the your fields here
new EmailField("Email", "", "Email address..."),
         new TextField("Company", "", "Company..."),
         new TextField("Country", "", "Country...")

), new FieldSet(
// List the action buttons here
new FormAction("signup", "")

), new RequiredFields(
new EmailField("Email", "", "Email address..."),
         new TextField("Company", "", "Company..."),
         new TextField("Country", "", "Country...")
));
}
function signup($data, $form) {
   $member = new Member();
$form->saveInto($BetaTesterForm);
      $member->write();
      $member->Groups()->add(2);
      Director::redirect('thanks-for-registering/');
      
}
}

also... I did try to look this up in docs before asking, it's just that dummies like me dont even know that 'Members' exist, so we look up 'adding form fields to admin' which doesn't come up with any results...

Avatar
Simon

Core Development Team, 27 Posts

17 November 2006 at 2:24pm

Your using the wrong function on getCMSFields() - see below.

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main",new TextField("Company"));
$fields->addFieldToTab(Root.Content.Main",new TextField("Country"));
return $fields;
}

everything else looks good :-)