For the complete documentation index, see llms.txt. This page is also available as Markdown.

acpt/form/authorize_field

Allow, skip or reject a single submitted form field before it is saved

Type: Filter

Available since ACPT 2.1.1.

Runs once for every field of a submitted front-end form, after validation and before anything is written to the database. Use it to decide, field by field, whether the current visitor may save that value.

By default the value is ACPT's own verdict: false when the meta field (or custom content type column) has permissions that don't let the current user edit it, true otherwise.

  • Return false to skip the field: its value is not saved, the rest of the form is saved normally.

  • Return a WP_Error to reject the whole submission: nothing is saved and the error message is shown next to the field.

Parameters

Parameter
Type
Description

$allowed

bool|WP_Error

ACPT's own verdict (see above)

$datum

array

The sanitized submitted value: id, name, type, value, extra, and the flags isMeta, isPost, isTerm, isUser

$field

FormFieldModel

The form field (use getMetaField() to reach the linked ACPT meta field, if any)

$form

FormModel

The form being submitted

Return: true to save the field, false to skip it, a WP_Error to reject the submission.

Usage

use ACPT\Core\Models\Form\FormFieldModel;
use ACPT\Core\Models\Form\FormModel;

add_filter("acpt/form/authorize_field", function($allowed, array $datum, FormFieldModel $field, FormModel $form){
    // the "price" field can only be changed by shop managers
    if ($datum['name'] === 'product_box_price' && !current_user_can('manage_woocommerce')) {
        return new WP_Error('acpt_read_only', 'You cannot change the price.');
    }

    return $allowed;
}, 10, 4);

See also acpt/form/authorize_submission to allow or reject the submission as a whole.

Last updated