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