This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
If you have a multi-page form, you can use this filter to display the same field multiple times.
Usage
add_filter('frm_get_paged_fields', 'get_extra_form_fields', 10, 3); function get_extra_form_fields($fields, $form_id, $error=false)
Parameters
- $fields (array)
- $form_id (integer)
- $error (boolean - whether or not there was a validation error on the page )
Examples
Show all fields on the final page of a multi-paged form
This code will get all the specified fields and display them on the last page of the form. These fields will still appear in their normal position as well.
add_filter('frm_get_paged_fields', 'get_extra_form_fields', 30, 3);
function get_extra_form_fields($fields, $form_id, $error=false){
if($form_id == 25){ //change 25 to the id of the form to change
$prev_page = FrmAppHelper::get_param('frm_page_order_'. $form_id, false);
if($prev_page > 3){ //change 3 to a number higher than the order of second to last page break
$new_fields = FrmField::getAll( 'fi.id in (45,46)', 'field_order' ); //change 45,46 to the IDs of the fields you'd like to show on the last page
$fields = array_merge($fields, $new_fields); //if you want to mess with the order, you can tinker with this on your own
}
}
return $fields;
}
The $prev_page > 3 is a bit confusing. In my example, I had a page break that was the 5th field in the form, so pick a number smaller than that, but bigger than any previous page breaks.
Remove page breaks from the admin
Use this if you would like your form to all be one a single page when you are creating or editing an entry from the back-end.
Note: This snippet is not intended for use with repeater fields.
add_filter( 'frm_get_paged_fields', 'remove_my_breaks', 9, 2 );
function remove_my_breaks( $fields, $form_id ) {
if ( ! is_admin() ) {
return $fields;
}
if ( $form_id == 12 ) { // change 12 to the ID of your form
remove_filter( 'frm_get_paged_fields', 'FrmProFieldsHelper::get_form_fields', 10, 3 );
foreach( (array) $fields as $k => $f ) {
if ( $f->type == 'break' ) {
unset( $fields[ $k ] );
}
}
}
return $fields;
}
If you want to remove page breaks on the front-end, remove the following from the above example:
if ( ! is_admin() ) {
return $fields;
}
Randomize Field Order
Each time the form is loaded, the order of the fields on the current page will be randomized. The user experience will be best if ajax submit is turned on to prevent page reload and field reordering.
add_filter( 'frm_get_paged_fields', 'randomize_form_fields', 20, 2 );
function randomize_form_fields( $fields, $form_id ){
if ( $form_id == 25 ) { //change 25 to the id of the form to change
shuffle( $fields );
}
return $fields;
}