Customized registration form with post creation – recently stopped working
-
Sometime in the past month or so this form has stopped working. Initially the error happened at the final page: the “register” (submit) button does nothing at all. No error showing in console either.
Now a new error occurs much earlier in the form, when trying to advance from the “Race 1” (3rd) page of the form: error message says “This field is required. Please enter the post title.” This didn’t happen before. The form creates 5 posts (custom posts) as part of the registration process. The post title is created during submission via a custom plugin that uses some of the field entries (plugin created via guidance from this forum). It was working perfectly for over 2 years.
There are a number of customizations (mu-plugins) that were created with guidance from this forum, so I’m wondering if some of that custom code has become obsolete after plugin updates.
We have a similar form that is not a registration form, that also creates up to 5 of the same type of custom post, and the same issue now happens there after trying to advance past Race 1. “This field is required. Please enter the post title.”
Another form we have that submits only a single post IS working, no error about required post title. It’s creating the same custom post type and auto creating the title via a mu-plugin. But that is a one-page form. So maybe it’s related to multi page forms?
Here are the customizations (mu-plugins) being used. Note the form ID is 513.
Creating the post titles:
<?php
/**
* Plugin Name: Forminator Results Auto Post Title for Registration Form
* Description: Creates results post title from submitter name and date/time of submission.
* Author: WPMU Dev plus customizations by Teresa Nightingale
*/
add_filter( 'forminator_prepared_data', 'wpmudev_update_post_data_fields_reg', 10, 2 );
function wpmudev_update_post_data_fields_reg( $prepared_data, $module_object ){
if( 513 != $module_object->id ){
return $prepared_data;
}
if( isset( $prepared_data[ 'postdata-1' ] ) ){
if( isset( $prepared_data[ 'postdata-1' ][ 'country' ] ) ){
$countryname1 = get_term( $prepared_data[ 'postdata-1' ][ 'country' ] )->name;
} else {
$countryname1 = '';
}
$prepared_data[ 'postdata-1' ][ 'post-title' ] = $countryname1 . ' race result for ' . $prepared_data[ 'name-1' ][ 'first-name' ] . ' ' . $prepared_data[ 'name-1' ][ 'last-name' ];
}
if( isset( $prepared_data[ 'postdata-2' ] ) ){
if( isset( $prepared_data[ 'postdata-2' ][ 'country' ] ) ){
$countryname2 = get_term( $prepared_data[ 'postdata-2' ][ 'country' ] )->name;
} else {
$countryname2 = '';
}
$prepared_data[ 'postdata-2' ][ 'post-title' ] = $countryname2 . ' race result for ' . $prepared_data[ 'name-1' ][ 'first-name' ] . ' ' . $prepared_data[ 'name-1' ][ 'last-name' ];
}
if( isset( $prepared_data[ 'postdata-3' ] ) ){
if( isset( $prepared_data[ 'postdata-3' ][ 'country' ] ) ){
$countryname3 = get_term( $prepared_data[ 'postdata-3' ][ 'country' ] )->name;
} else {
$countryname3 = '';
}
$prepared_data[ 'postdata-3' ][ 'post-title' ] = $countryname3 . ' race result for ' . $prepared_data[ 'name-1' ][ 'first-name' ] . ' ' . $prepared_data[ 'name-1' ][ 'last-name' ];
}
if( isset( $prepared_data[ 'postdata-4' ] ) ){
if( isset( $prepared_data[ 'postdata-4' ][ 'country' ] ) ){
$countryname4 = get_term( $prepared_data[ 'postdata-4' ][ 'country' ] )->name;
} else {
$countryname4 = '';
}
$prepared_data[ 'postdata-4' ][ 'post-title' ] = $countryname4 . ' race result for ' . $prepared_data[ 'name-1' ][ 'first-name' ] . ' ' . $prepared_data[ 'name-1' ][ 'last-name' ];
}
if( isset( $prepared_data[ 'postdata-5' ] ) ){
if( isset( $prepared_data[ 'postdata-5' ][ 'country' ] ) ){
$countryname5 = get_term( $prepared_data[ 'postdata-5' ][ 'country' ] )->name;
} else {
$countryname5 = '';
}
$prepared_data[ 'postdata-5' ][ 'post-title' ] = $countryname5 . ' race result for ' . $prepared_data[ 'name-1' ][ 'first-name' ] . ' ' . $prepared_data[ 'name-1' ][ 'last-name' ];
}
return $prepared_data;
}Fix bug with missing custom taxonomy in stored submissions:
<?php
/**
* Plugin Name: Forminator Postdata Submission Country
* Description: Fixes bug where custom taxonomy term Country is missing from stored submissions. Works for single or multiple country selections.
* Author: WPMU Dev
*/
add_filter( 'forminator_entry_meta_value_to_string', 'wpmudev_show_post_country_entry', 10, 5 );
function wpmudev_show_post_country_entry( $string_value, $field_type, $meta_value, $allow_html, $truncate ){
if( $field_type == 'postdata' ){
if( ! empty( $meta_value['postdata'] ) ){
if( !empty( $meta_value['value']['country'] ) ){
$post_country = $meta_value['value']['country'];
$the_countries = '';
$countegories = 0;
$single_label = esc_html__( 'Country', 'forminator' );
if ( is_array( $post_country ) ) {
foreach( $post_country as $country ) {
$countries[] = get_the_category_by_ID( $country );
}
$countegories = count( $countries );
$the_countries = implode( '; ', $countries );
} else {
$the_countries = get_the_category_by_ID( $post_country );
}
if ( $allow_html ) {
$value = '<hr>';
if ( is_array( $post_country ) ) {
$value .= '<strong>' . esc_html( _n( 'Country', 'Countries', $countegories, 'forminator' ) ) . ':</strong> ';
} else {
$value .= '<strong>' . $single_label . ':</strong> ';
}
$value .= $the_countries;
} else {
$value .= $single_label . ': ';
$value .= $the_countries . ' | ';
}
$value .= '<hr>';
$string_value .= $value;
}
}
}
return $string_value;
}Fix bug where custom taxonomy is missing from email notifications:
<?php
/**
* Plugin Name: Forminator Postdata Submission Fix for Results
* Description: Fixes bug where custom taxonomy is missing from the email notifications using postdata fields - for forms collecting race results. Up to 5 results at a time.
* Author: WPMU Dev
*/
add_filter( 'forminator_replace_form_data', 'wpmudev_post_data_macros_results', 10, 3 );
function wpmudev_post_data_macros_results( $content, $data, $original_content ){
if( !( $data['form_id'] == 576 || $data['form_id'] == 513 || $data['form_id'] == 677 || $data['form_id'] == 1373 ) ){ // it's not one of the forms that collect race results post data
return $content;
}
if( !isset( $data['postdata-1'] ) ){
return $content;
}
if( strpos( $content, '{post-term}' ) !== false ){
if( isset( $data['postdata-1']['country'] ) ){
$term_name = get_term( $data['postdata-1']['country'] )->name;
$content = str_replace( '{post-term}', $term_name, $content );
}
}
if( !isset( $data['postdata-2'] ) ){
return $content;
}
if( strpos( $content, '{post-term-2}' ) !== false ){
if( isset( $data['postdata-2']['country'] ) ){
$term_name2 = get_term( $data['postdata-2']['country'] )->name;
$content = str_replace( '{post-term-2}', $term_name2, $content );
}
}
if( !isset( $data['postdata-3'] ) ){
return $content;
}
if( strpos( $content, '{post-term-3}' ) !== false ){
if( isset( $data['postdata-3']['country'] ) ){
$term_name3 = get_term( $data['postdata-3']['country'] )->name;
$content = str_replace( '{post-term-3}', $term_name3, $content );
}
}
if( !isset( $data['postdata-4'] ) ){
return $content;
}
if( strpos( $content, '{post-term-4}' ) !== false ){
if( isset( $data['postdata-4']['country'] ) ){
$term_name4 = get_term( $data['postdata-4']['country'] )->name;
$content = str_replace( '{post-term-4}', $term_name4, $content );
}
}
if( !isset( $data['postdata-5'] ) ){
return $content;
}
if( strpos( $content, '{post-term-5}' ) !== false ){
if( isset( $data['postdata-5']['country'] ) ){
$term_name5 = get_term( $data['postdata-5']['country'] )->name;
$content = str_replace( '{post-term-5}', $term_name5, $content );
}
}
return $content;
}Convert custom taxonomy simple dropdown select to search box type select:
<?php
/**
* Plugin Name: Forminator Search Box for Countries in Postdata
* Description: converts simple select dropdown for country taxonomy in post-data field to search box type select.
* Author: WPMU Dev
*/
add_filter( 'forminator_field_postdata_country', 'wpmudev_allow_search_taxonomy_data', 10, 1 );
function wpmudev_allow_search_taxonomy_data( $html ) {
$html = str_replace( 'type="select"' , 'type="select" data-search="true"', $html );
$html = str_replace( 'placeholder=""' , 'data-placeholder="--Select a Country--"', $html );
$html = str_replace( '<option value="288"' , '<option></option> <option value="288"', $html );
return $html;
}The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.