Forms on multilingual sites (WPML)
Forms use CAFE's WPML integration like edit screens do.
- Labels and instructions are shown in the current language (the same
cafe_field_label/cafe_field_instructionstranslations as edit screens). - Edit forms on a translation: fields set to Copy show the original's value read-only and are never saved from the form; Translate fields save on the translation; Copy once fields are editable.
- Create forms: WPML gives the new post a language when it is saved,
normally the language of the request. AJAX submits go through the REST API;
check on your site that new posts get the language you expect, and set it
in
cafe_dynamic_form_savedwith WPML'swpml_set_element_language_detailsaction if not. - Form texts you pass as arguments (
submit_label,success_message) are plain strings. Translate them in PHP:
cafe_dynamic_form( [
'id' => 'new-event',
'field_groups' => [ 'group_event_details' ],
'submit_label' => __( 'Send event', 'my-theme' ),
'success_message' => __( 'Thanks! We will review your event.', 'my-theme' ),
] );
Forms made in CAFE → Forms keep their texts in one language; use
cafe_dynamic_form_args to translate them:
add_filter( 'cafe_dynamic_form_args', function ( array $args ) {
if ( 'event-sign-up' === ( $args['id'] ?? '' ) ) {
$args['submit_label'] = __( 'Send event', 'my-theme' );
}
return $args;
} );
- Redirects: use a translated address, e.g. with
apply_filters( 'wpml_permalink', $url )incafe_dynamic_form_redirect.
See also WPML.