10689 Posts in 2796 Topics by 1518 members
Jump to:If this is your first visit, you will need to register before you can post. However, you can browse all messages below.
| Page: 1 | go to end | Reply | |
| Author | Topic: Completely lost on Ajax forms | 762 views |

28 March 2008 at 1:25pm
I have not been able to figure out how to get a form to submit using Ajax. There is mention of using a FormResponse object here. But then there is no documentation for it.
I have this in my Page_Controller class (NB: Haven't even started on DataObject stuff yet - just want to see this submitting via ajax):
// Create actions
$actions = new FieldSet(
new AjaxFormAction('doContactUsForm', 'Submit'),
new ResetFormAction('doCloseContactUsForm', 'Close')
);
$reqdFields = new RequiredFields("Email", "FirstName");
return new Form($this, 'ContactUsForm', $fields, $actions);//, $reqdFields);
}
function doContactUsForm($data, $form) {
// your form actions
FormResponse::update_dom_id('ContactFormLiner', '<p>DONE</p>');
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();
}
Last edited: 28 March 2008 at 1:28pm

31 March 2008 at 6:24pm
Is this just a matter of copying the PageCommentInterface.js example or is there an easier "built-in" method?

1 April 2008 at 10:31am
AjaxFormAction is only used in specific cms interfaces, we're discussing deprecating it in a sapphire-framework-context, see http://open.silverstripe.com/ticket/2353
PageCommentInterface.js is a good start, you just need basic PrototypeJS functionality to achieve what you're trying to do: http://prototypejs.org/api/ajax/request
You can still use the FormResponse class, just make sure you evaluate the ajax-response rather than simply outputting it (we have a little wrapper called Ajax.Evaluator for this)
| 762 views | |||
| go to top | Reply |