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.


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

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

Adding user fields + Register function + Admin area SLOW


18 Posts   4991 Views


16 October 2008 at 1:01am Forum Moderator, 5511 Posts

Yes. Have a read of the tutorials and they will cover some examples of adding 'DataObjects' esp the forms one - #3.


16 October 2008 at 10:44am Community Member, 36 Posts

In that tutorial the submissions are added to the database once by each person, then retrieved as a whole.

Is it possible to save the users ID in the submission, so it would be possible to view the results of a single user?

$submissions = DataObject::get('BrowserPollSubmission');
That gets them all. Wouldn't it be slow if there were many fields, you only needed to view one users set of answers, and there were thousands of sets?


16 October 2008 at 12:17pm Forum Moderator, 5511 Posts

I fully recommend you read the docs (as painful as they are) before you post. DataObject::get() has a number of parameters which you can use to filter down. Eg

DataObject::get(Object, SQL Filter Statement, Sort Option, Join Fields, Limit on how many to return);

And you can leave off any of the last 4 or pass "". So to get all the submissions from a user ID...

DataObject::get("Submission", "UserID = '$SomeID'");

UserID is the field on the Submission Object and $SomeID is a number :)


16 October 2008 at 12:40pm (Last edited: 16 October 2008 12:40pm), Community Member, 36 Posts

I can't find any documentation about this... - is it in there? Or somewhere in


16 October 2008 at 12:50pm Forum Moderator, 5511 Posts is a useful page


16 October 2008 at 1:07pm Community Member, 36 Posts

So I could do this:

function doform($data, $form) { //what is the difference between data and form?
$myPlayer = new Player();
$myPlayer->UserID = Member::currentUserID();
$myPlayer->Firstname = $form->Firstname; // or $data->Firstname
$myPlayer->Surname = $form->Surname; // or $data->Surname
} else {
// Not logged in


16 October 2008 at 1:49pm Forum Moderator, 5511 Posts

Yes you are on the correct track. Though the $data is not an object it is a standard php array of data where the key is your field name so if you have a TextField('Firstname') the value in the submitted function would be $data['Firstname'].

The other thing you can do is if your field names in your form match the fields names in the dataobject eg your 'Player' has Firstname you can call a method called saveInto() which is a feature on the form. It will take all the data from $data and try and save into the dataobject

function doform($data, $form) {
$player = new Player();
$player->UserID = Member::currentUserID(); // save the ID


16 October 2008 at 11:16pm (Last edited: 17 October 2008 12:56am), Community Member, 36 Posts

Thanks for all of the help!

-- With some midnight coding and some trying it out for myself, I have solved the first two of my problems. Now for some sleep =D

I have come up with this:
(you need code highlighting)
- That is my form - it handles the display of the form and the submission.

And I have my database PHP file:
class MedCheck extends DataObject {
static $db = array(
"UserID" => "Int",
"Field1" => "Text",
"Field2" => "Text",
"Field3" => "Text"

At the moment I have three problems.

The main problem is that I'm not sure how to output data from DataObject::get().
At the moment I have:

function ViewInfo() {
$info = DataObject::get_one("MedCheck", "UserID = '1'");
foreach($info as $key => $value){
echo "$key: $value";

Which isn't working. It comes up with "0: MedCheck" at the top of the page, not with the rest of the content.

EDIT: echo $info->Field1; seemed to work, building on that...
EDIT: return instead of echo works perfectly!

EDIT: woot! progress!

function ViewInfo() {
$info = DataObject::get_one("MedCheck", "UserID = '" . Member::currentUserID() . "'");
return "<p><b>Information for user $info->UserID</b><br />
$info->Field1<br />
$info->Field2<br />

EDIT: got that sorted. Now I need the drop down list.

The second problem is that I'm not sure how to have a drop down list of all of the users, with the values of the drop down list as the corresponding user ID. Then use the submission of that to show information about that user (by passing the corresponding user ID to another function, not put the submission into the database).

EDIT: WOOT even more progress! I have the drop down menu working, but I can't do anything with the values yet. Here it is - could you see why my doform shows absolutely nothing?

EDIT: nuuu.. i took data as an object not an array. Still need help with sending the form data to another page to use in php.

$this->customise($data)->renderWith(array('Page_results', 'Page'));
I'm guessing that won't work because it passes it for use in the .ss page, not the .php page.

EDIT (yet again): I worked it out! I have done it! Woot!
Hopefully using the GET method is acceptable (with the security: (int)$_GET[...)
(midnight coding lol)
Now on to the next problem:

The third problem is I want only one submission allowed for each user, and if the user submits again it updates the previous submission. I saw in the datamodel documentation it talked about 'relations' with the 'has_one' array. How would I implement that?