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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Problem creating an update form


Go to End


1003 Views

Avatar
esakrielaart

Community Member, 59 Posts

28 August 2011 at 10:22pm

Hello,

I am trying to build a update form, that is, a form that contains prefilled data allready known from a user and where the user can change this data and saves the form again. I allready a working 'first-time' form, and also the 'next-time' form is working, including showing the data known from the user.

When I save the form it somehows adds a fieldname value 0, so Silverstripe tries to execute a DB query like "UPDATE tableName SET someKey = someValue, ..., "0" = '0'

How can I remove this strange and undesired 0 fieldname? This is what I based on:

$fields = new FieldSet(
		new TextField('Voorletters','Voorletters',(isset($myObj->Voorletters) ? $myObj->Voorletters : "") ),
		new TextField('FirstName','Voornaam',(isset($myObj->FirstName) ? $myObj->FirstName : "") ),
		new TextField('Surname','Achternaam',(isset($myObj->Surname) ? $myObj->Surname : "") ),
		new OptionSetField('Geslacht', 'Geslacht', array('m' => 'Man', 'v' => 'Vrouw'), (isset($myObj->Geslacht) ? $myObj->Geslacht : "") ),
		new EmailField('Email','Email',(isset($myObj->Email) ? $myObj->Email : "") ),
		new PasswordField('Password','Wachtwoord',(isset($myObj->Password) ? $myObj->Password : "") ),
		new TextField('Adres','Adres',(isset($myObj->Adres) ? $myObj->Adres : "") ),
		new TextField('Postcode','Postcode',(isset($myObj->Postcode) ? $myObj->Postcode : "") ),
		new TextField('Plaats','Plaats',(isset($myObj->Plaats) ? $myObj->Plaats : "") ),
		new TextField('Telefoon','Telefoonnummer',(isset($myObj->TelefoonNr) ? $myObj->TelefoonNr : "") ),
		new TextField('XtraCardNr','XtraCardNr',(isset($myObj->XtraCardNr) ? $myObj->XtraCardNr : "") )

		);
// Other stuff is as in every tutorial
// ...
return $form

And the processing function:

$cMember = Member::currentUserID();
	$subscription = Member::get_by_id('DanceMemberInfo', $cMember);
	$form->saveInto($subscription);
	
	return print_r($subscription);
	// Sla de nieuwe regel op
	if($subscription->write()) {
	    Director::redirectBack();
	    return;
	}

Does anybody spot the problem? Maybe I am using the wrong approach to saving updated data, but I can't find any other tutorials on this.

Thanks,
Maurice