Class FormResponse
This class collects all output that needs to be returned after an Form-Request to the client. It automatically determines if it needs to send back javascript after an Ajax-Request or just redirect to another page (on a normal request).
FormResponse is also responsible for keeping the client- and serverside in sync after an HTTP-Request by collecting javascript-commands (which mostly trigger subsequent update-calls by Ajax.) Use the output as a return-value for Ajax-based saving methods. Be sure to check if the call is acutally "ajaxy" by checking Director::is_ajax(). It is the developers responsibility to include this into his custom form-methods. Use the Request-Parameter 'htmlonly' to enforce a pure HTML-response from the client-side.
Example: A {@TableField} is in an incorrect state after being saved, as it still has rows marked as "new" which are already saved (and have an ID) in the database. By using AjaxSynchroniser we make sure that every instance is refreshed by Ajax and reflects the correct state.
Caution:
- FormResponse assumes that prototype.js is included on the client-side. (We can't put it into Requirements because it has to be included BEFORE an AjaxSynchroniser is called).
- Please DON'T escape literal parameters which are passed to FormResponse, they are escaped automatically.
- Some functions assume a {LeftAndMain}-based environment (e.g. load_form())
Methods summary
public static
string
|
|
public static
|
|
public static
|
|
public static
|
|
public static
|
|
public static
|
#
status_message( mixed $message = "", mixed $status = null )
Sets the status-message (overlay-notification in the CMS). You can call this method multiple times, it will default to the "worst" statusmessage. |
public static
|
|
public static
|
#
update_status( mixed $status, mixed $form = "Form_EditForm" )
Update the status (upper right corner) of the given Form |
public static
|
|
public static
|
#
set_non_ajax_content( mixed $content )
Fallback-method to supply normal HTML-response when not being called by ajax. |
public static
|
|
public static
string
|
|
public static
|
#
update_dom_id( mixed $domID, mixed $domContent, mixed $reapplyBehaviour = true, mixed $replaceMethod = 'replace', mixed $uniquenessID = null )
Replace a given DOM-element with the given content. It automatically prefills {$non_ajax_content} with the passed content (as a fallback). |
protected static
string
|
Magic methods summary
Properties summary
protected static
array
|
$rules |
#
array |
protected static
array
|
$behaviour_apply_rules |
#
array Separated from $rules because we need to apply all behaviour at the very end of the evaluated script to make sure we include all possible Behaviour.register()-calls. |
protected static
mixed
|
$non_ajax_content |
#
string |
protected static
array
|
$status_messages |
#
Status-messages are accumulated, and the "worst" is chosen |
protected static
mixed
|
$redirect_url |
#
string |
protected static
array
|
$status_include_order |
#
string |