Thanks Martin. I have followed these and all all seem to be working. My problem is with this part of the guide from the form:recipes.
class RegistrationForm_Controller extends Page_Controller {
function doform($data, $form) {
// your form actions
FormResponse::update_dom_id('myForm', '<form>myformcontent</form>');
FormResponse::status_message('Done', 'good');
// will automatically show the status-message if called by ajax, or redirect on a normal HTTP-request
return FormResponse::respond()
}
}
I note the line "will automatically show the status-message if called by ajax, or redirect on a normal HTTP-request"
I can not get my form to do anything other than the normal HTTP-request post submit.
Here are the relevant code snippets. I am sure I am missing something obvious, I should maybe point out that I am new to the AJAX world! (if that was not obvious already!).
Any help much appreciated.
Thanks in advance.
The form:
function Studentedit() {
$goeditid=Session::get('goeditid');
// debug::show($goeditid);
$student = DataObject::get_by_id('Student',$goeditid);
// $student = DataObject::get_by_id('Student',$_GET['id']);
$actions = new FieldSet(
new FormAction('doUpdateStudent','Save')
);
if ($student) {
$form= new StudentForm2($this,'StudentEdit',$actions);
$form->loadDataFrom($student);
return $form;
}
else {
return $this->httpError(404,'Sorry, student does not exist');
}
}
The submit method:
function doUpdateStudent($data,$form) {
$student = DataObject::get_by_id('Student',$data['ID']);
if ($student) {
$form->saveInto($student);
$student->write();
}
if($this->isAjax) {
FormResponse::update_dom_id('ajaxEditForm', '<p>DONE</p>');
FormResponse::status_message('Done', 'good');
}
else {
return Array();
}
return FormResponse::respond();
}