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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

How to do insert data to table member in custom fields ?


Reply

2131 Views

Avatar
jQuery.in.th

24 August 2009 at 9:34pm (Last edited: 24 August 2009 9:35pm), Community Member, 7 Posts

Hi,

I have created class RegisterMember and created register form please see image below.

[url=http://www.uploadd.com/imageUpload/image.aspx?img=35C13B69A4ZJ8AOIUYWJT4BH8H66MD][/url]
My class .

<?php

/**
* Page containing a registration form.
* Uses Member::getMemberFormFields() to know what to ask of a user.
*/
class RegisterPage extends Page {
static $db = array(
"ThanksTitle" => "HTMLVarchar",
"ThanksContent" => "HTMLText",
);

function getCMSFields($cms) {
$fields = parent::getCMSFields($cms);

$fields->addFieldsToTab("Root.Content.Thanks", array(
new TextField("ThanksTitle", "Title"),
new HTMLEditorField("ThanksContent", "Content"),
));

return $fields;
}

}

class RegisterPage_Controller extends Page_Controller {
/**
* Return the edit form for the current user
*/
function Form() {
// Get the fields from a new member - seems like a good default :-)

$businessArr = array(
'Corporate reseller'=>'Corporate reseller',
'System Integrator'=>'System Integrator',
'OEM'=>'OEM',
'Distributor'=>'Distributor',
'Online Retailer'=>'Online Retailer',
'Value Added Reseller'=>'Value Added Reseller'
);
$marketSegmentArr = array(
'End consumers'=>'End consumers',
'Small office/ home office'=>'Small office/ home office',
'Small and medium businesses'=>'Small and medium businesses',
'Enterprise businesses'=>'Enterprise businesses',
);

$member = new Member();
$fields = new FieldSet(
new TextField('FirstName','First Name'),
new TextField('LastName','Last Name'),
new TextField('CompanyName','Company Name'),
new TextField('Address1','Address 1'),
new TextField('Address2','Address 2'),
new TextField('Town','Town'),
new TextField('PostalCode','Postal Code'),
new TextField('Country','Country'),
new TextField('TelNumber','Tel Number'),
new EmailField('EmailAddress','Email Address'),
new DropdownField(
$name = 'Business',
$title = 'Please select the primary category that best describes your business.',
$businessArr
),
new DropdownField(
$name = 'MarketSegment',
$title = 'Which of the following market segments does your organisation sell to?',
$marketSegmentArr
)
);

$actions = new FieldSet(
new FormAction('register', 'Register')
);

$form = new Form($this, 'Form', $fields, $actions);

return $form;
}

/**
* Save the profile details
*/
function register($data, $form) {
// Create a new member and save the form into it
$member = new Member();
$form->saveInto($member);

// Write to the databsae
$member->write();

// To do: add a status message on the form, using the standard form message system

// Return to the original form
Director::redirect($this->Link() . 'thanks');
}

function thanks() {
return array(
'Title' => $this->ThanksTitle,
'Content' => $this->ThanksContent,
'Form' => ' ',
);
}
}

I have tested submit register form and I have view data in phpMyAdmin. In table member no has data.

Database :
[url=http://www.uploadd.com/imageUpload/image.aspx?img=35C13B68D6G7Q4I9PQ2RYU5L6VYW3R][/url]

Please help me.