21294 Posts in 5734 Topics by 2602 members
| Go to End | Next > | |
| Author | Topic: | 1952 Views |
-
[SOLVED] OptionsetField not saving, please help

8 January 2011 at 4:36am Last edited: 8 January 2011 4:37am
Help! I've built a form in the latest release of SS and now I'm having trouble saving the information where I have 'Optionsetfield', all the other field types save perfectly ok.
I've used these before and not encountered this so I guess I'm just missing something here but on reading the documentation I can't spot anything.
Here is my code:
public function ResultsEditForm(){
$urlAction = Director::URLParam('Action');
$urlID = Convert::raw2sql(Director::urlParam('ID'));if(is_numeric($urlID)){
$Contact = $caseInfo->Contact;
}// Create fields for edit form
$fields = new FieldSet(new OptionsetField(
$name ='Contact',
$title = 'Contact',
$source = array(
"1" => "Yes",
"2" => "No"
), $value = $Contact)
);
$actions = new FieldSet(
new FormAction("UpdateCase", "Update")
);
return new Form($this, "ResultsEditForm", $fields, $actions);
}// Function to write our data
public function UpdateCase($data, $form){
$id = (int)$_REQUEST['CaseID'];
$caseInfo = DataObject::get_by_id('myFifth', $Case->myFifthID);
$caseInfo->Contact = $data['Contact'];
$caseInfo->write();
}
Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");
}public function Success(){
return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";
}I think I've included everything above, I've not posted the other fields as this post would be very very long.
I've tried making the OptionsetField a DropdownField to see how they differ and it made no difference when saving.
I'm close to a deadline here so quite anxious, this is the only thing holding me back, any help much appreciated, thanks.
-
Re: [SOLVED] OptionsetField not saving, please help

8 January 2011 at 5:26am
a) have you Debug:show($data) in UpdateCase? this will confirm that the code is called and 'Contact' has the right value to place there. For eaxmplae hardcoding the 'Contact' in that function might work, but the value in $data might be wrong...
-
Re: [SOLVED] OptionsetField not saving, please help

8 January 2011 at 5:29am Last edited: 8 January 2011 5:33am
Hi Swaiba,
Thanks for your reply, yes I had debugged and the correct value seemed to be showing, it struck me that maybe the form is not saving the optionsetfields for some strange reason because if I change the value in the database via phpMyAdmin and then refresh my page it picks up the value ok, only each time I save it, it default to a '1' boolean value.
-
Re: [SOLVED] OptionsetField not saving, please help

8 January 2011 at 5:33am
You mean that you select "Yes", that maps to "1" and it saves that is the field? is that right?
Maybe you need to have...
$source = array(
"Yes" => "Yes",
"No" => "No" );what does you DO look like?
-
Re: [SOLVED] OptionsetField not saving, please help

8 January 2011 at 5:38am
I think the way I have it is correct, basically if you select "Yes" it would be a value of '1' and if you select "No" it would be a value of '2'.
Regardless of what you select it will save it as a value of 1, even with the code you have suggested.
The code looks ok acording to the documentation also, is it possible this could be a bug?
-
Re: [SOLVED] OptionsetField not saving, please help

8 January 2011 at 5:39am
What does you DataObject 'myFifth' look like?
-
Re: [SOLVED] OptionsetField not saving, please help

8 January 2011 at 5:46am
yeah looks fine, but maybe this would help... changing...
$id = (int)$_REQUEST['CaseID'];
$caseInfo = DataObject::get_by_id('myFifth', $Case->myFifthID);
$caseInfo->Contact = $data['Contact'];
$caseInfo->write();to...
$caseInfo = DataObject::get_by_id('myFifth', (int)$_REQUEST['CaseID']);
$caseInfo->Contact = $data['Contact'];
$caseInfo->write();
| 1952 Views | ||
| Go to Top | Next > |


