![]() The hashed name of the variable that should reference the entry, if a validation error occurs. (Defaults to enabled.)įallback if sourceId isn’t passed, for backwards compatibility. Whether the entry should be enabled ( 1/ 0). ![]() Whether the entry should be enabled for the entry’s siteId ( 1/ 0), or an array of site IDs that the entry should be enabled for. (Defaults to the entry’s current author, or the logged-in user.)Ĭanonical (non-draft, non-revision) entry ID to update. The ID of the user account that should be set as the entry author. The exact message will be specific to the failure mode, and can be overridden using the globally-supported failMessage param. See a complete example of how to handle this in the models and validation section.įor requests that include an Accept: application/json header, Craft will instead build a JSON object with an errors key set to a list of the model’s errors (indexed by attribute or field), a message key, an array representation of the model, and a modelName key with the location of the model data in the payload. By virtue of being part of the same request that populated and validated a model, Craft is able to pass it all the way through to the rendered template-making it possible to repopulate inputs and display errors, contextually. In all but rare, unrecoverable cases, Craft sets an error flash describing the issue, and carries on serving the page at the original path (either the page the request came from, or whatever was in the originating attribute). We’ll use the term “model” here for technical reasons-but elements are models, too! # Failureįailed responses are mostly handled via the craft\web\Controller::asModelFailure() (opens new window) or asFailure() (opens new window) methods. Additional action-specific properties are also returned at the top level of the response object. ![]() ![]() In addition to the redirect property, the response object will include a message key with the same text that would have been flashed (for a text/html response)-either a specific message from Craft, or one provided in the request via the globally-supported successMessage param. Helper for fetching a CSRF token: const getSessionInfo = function ( ), in the example) whose values aren’t yet known.įor JSON responses, redirection does’t make as much sense-so Craft will include the resolved redirect value for your client to navigate programmatically (say, via window.location = resp.redirect). Some tools (like jQuery) need no configuration others (like the native fetch() API (opens new window)) will need to be configured explicitly: In order to respond appropriately, Craft requires that Ajax requests are identified as such. Override success-condition flash messages. Generates a hidden HTML element to control redirection after successful requests. Lower-level helper for generating hidden HTML inputs.Įven finer-grained control over HTML element creation. Generate a hidden HTML required for CSRF protection. Generate an absolute URL to the specified action, with any extra params. Generate a hidden HTML element for controlling which action a should route to. # POSTĪll POST requests are made through forms or Ajax, and require an action parameter and CSRF token. Using an unsupported method will throw a yii\web\BadRequestHttpException (opens new window), and show your error template with a 400 statusCode-or send a JSON response with an error key. # HTTP VerbsĮach action usually responds to one HTTP method (opens new window). This attribute has no effect if a redirect is issued in response to the request!Ĭraft also supports routing to specific actions using a path (beginning with the actionTrigger setting), or by creating an rule in routes.php. When an action param is not present in the request, you can use an “action path” like action="/actions/users/login".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |