render( $form_id_or_key, $atts );
$output = ob_get_clean();
return $output;
}
}
function allowed_html_tags( $tags, $context ) {
global $allowedposttags, $allowedamemtags;
if ( $context != 'amem' )
return $tags;
if ( is_array( $allowedamemtags) )
return $allowedamemtags;
$allowedamemtags = $allowedposttags;
$allowedamemtags['form'] = array(
'action' => true,
'accept' => true,
'accept-charset' => true,
'enctype' => true,
'method' => true,
'name' => true,
'target' => true,
);
$atts = array(
'type' => true,
'class' => true,
'id' => true,
'data-*' => true,
'aria-*' => true,
'name' => true,
'value' => true,
'checked' => true,
'disabled' => true,
'value' => true,
'multiple' => true,
);
$allowedamemtags['input'] = $atts;
$allowedamemtags['select'] = $atts;
$allowedamemtags['option'] = $atts;
return $allowedamemtags;
}
/**
* Renders the form specified by ID
*
* @since 1.0
*/
function render( $form_id_or_key, $args ) {
$form = amem_get_form( $form_id_or_key );
if ( ! $form || !$form['active'] ) {
return;
}
// Set global AMem Form
amem()->set_form($form, $args);
amem()->set_amem(true);
// Enqueue scripts and styles
amem_enqueue();
do_action( 'amem/form/enqueue', $form, $args );
do_action( 'amem/form/enqueue/type=' . $form['type'], $form, $args );
// Allow the form to be modified before rendering form
$form = apply_filters( 'amem/form/before_render', $form, $args );
$form = apply_filters( 'amem/form/before_render/type=' . $form['type'], $form, $args );
$args = wp_parse_args( $args, array(
'display_title' => false,
'display_description' => false,
'id' => $form['key'],
'values' => array(),
'submit_text' => $form['data']['submit_text'],//__( 'Submit', 'advanced-members' ),
'redirect' => null,
'target' => amem_get_current_url(),
'echo' => true,
'exclude_fields' => array(),
'uploader' => 'wp',
'filter_mode' => false,
'label_placement' => 'top',
'instruction_placement' => 'label',
'honeypot' => true,
) );
// Allow the arguments to be modified before rendering form
$args = apply_filters( 'amem/form/args', $args, $form );
$args = apply_filters( 'amem/form/args/type=' . $form['type'], $args, $form );
if ( $args['redirect'] === 'current' )
$args['redirect'] = amem_get_current_url();
// Allow a comma separated string for excluded fields
if ( is_string( $args['exclude_fields'] ) ) {
$args['exclude_fields'] = explode( ',', $args['exclude_fields'] );
}
// Set ACF uploader type setting
acf_update_setting( 'uploader', $args['uploader'] );
// Form element
// novalidate: avoid browser-locale HTML5 messages (e.g. Chrome KO "이 입력란을 작성하세요.")
// so required/empty checks use ACF/site language instead.
$form_attributes = array(
'class' => 'amem-form acf-form amem-form-type-' . $form['type'],
'method' => 'POST',
'action' => $args['target'],
'id' => $args['id'],
'data-key' => $form['key'],
'novalidate' => 'novalidate',
);
$form_ajax = isset($args['ajax']) ? $args['ajax'] : $form['data']['ajax'];
// Add data attribute to indicate that the form should use AJAX submissions
if ( $form_ajax ) {
$form_attributes['data-ajax'] = true;
}
$form_attributes = apply_filters( 'amem/form/attributes', $form_attributes, $form, $args );
$form_attributes = apply_filters( 'amem/form/attributes/type=' . $form['type'], $form_attributes, $form, $args );
echo sprintf( '
';
do_action( 'amem/form/after_render', $form, $args );
do_action( 'amem/form/after_render/type=' . $form['type'], $form, $args );
amem()->set_amem(false);// End of AMem Form
}
/**
* Renders all submission errors if any exist.
*
* @since 1.0
*/
function render_submission_error( $form, $args ) {
if ( amem_submission_failed( $form['key'] ) ) {
// $errors = amem()->submission['errors'];
$errors = amem()->errors->get_errors();
foreach ( $errors as $error ) {
echo '
';
echo sprintf( '
%s
', esc_html($error) );
echo '
';
}
}
}
/**
* Renders title and description of form if they should be shown.
*
* @since 1.0
*/
function render_title_and_description( $form, $args ) {
// Display title
if ( $args['display_title'] ) {
echo sprintf( '
';
}
/**
* Renders a field wrapper with all fields and a submit button.
*
* @since 1.0
*/
function render_fields( $form, $args ) {
// Get field groups for the form and display their fields
$field_groups = amem_get_form_field_groups( $form['key'] );
do_action( 'amem/form/before_field_wrapper', $form, $args );
do_action( 'amem/form/before_field_wrapper/type=' . $form['type'], $form, $args );
echo sprintf( '