stoodlee
Forum Replies Created
-
Thank you very much for your fantastic help! The MU Plugin code works perfectly. For people watching, or who come later for this answer, here is my documentation of the solution:
SOLUTION – to pre-populate a Form text field with the Page/Post Title
Requires “Must Use” WordPress plugin as described below
STEPS- Make sure to run a full site backup before you do anything
- PHP Code (note you MUST update with your Form ID and Text Field Name):
<?php /** * Plugin Name: WPMUDEV Forminator Form addition * Description: Pre-populate Form field Textarea-? with the Post/Page Title * The Post/Page title is put in a hidden field using standard Forminator settings * This code loads the hidden field value into the field Textarea-2 * Author: WPMU DEV * Reference: https://www.ads-software.com/support/topic/fill-a-field-with-the-current-page-post-title-2/ (october 2023) * License: GNU General Public License v3 or later * License URI: https://www.gnu.org/licenses/gpl-3.0.html */ add_action( 'forminator_before_form_render', 'wpmudev_post_data_form_check', 10, 5 ); function wpmudev_post_data_form_check( $id, $form_type, $post_id, $form_fields, $form_settings ) { if ( 4000 == $id ) { //Set number to your form ID add_filter( 'forminator_field_text_markup', 'wpmudev_add_post_page_title_text', 10, 2 ); } } function wpmudev_add_post_page_title_text( $html, $field ) { if ( $field[ 'element_id' ] != 'textarea-2' ) { //Put text field name in your form ID return $html; } $post_id = get_the_ID(); $title = forminator_get_post_data( 'post_title', $post_id ); $html = str_replace('</textarea>', "$title</textarea>", $html); return $html; }
- Place the code in a file (for example, wpumdev-prepopulate-title.php ) in the mu-plugins folder of your WordPress site
To create the folder and install the ‘Must Use’ code see https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins - Clear WordPress cache if needed
- When the Form is loaded on a Page or Post the textarea-2 field (as in code above) will be pre-filled with the Page or Post Title
Hi. Thanks for the quick response. I had used the native option “Embed Post/Page Title” for the Hidden Field.
But how do I then get that value into another input text field?
I want the field Textarea-2 pre-populated with the Post Title.
Here are screenshots of the form and fields:
https://snipboard.io/aA2pJ8.jpgAmazing support! The updated php file has worked. The issue was my Youtube videos are unlisted.
Thanks for your quick reply. I have created a staging site. The error is also in that system. I have logged a ticket at https://plugins360.com/support/ so you can check the site.
Hi @danieliser. Only this Plugin gave ‘not valid header’ when activating on the install screen. When I went to All Plugins menu and activated there it worked.
Thanks @karen1990 that worked for me. I did try another download but still same message activating on install screen. Activated fine from All Plugins and works
Same problem – when activating get “not valid header’ on a blank page. Tried both dashboard install and upload of the Zip from https://www.ads-software.com/plugins/content-control/
Deleted and re-installed several times.
Running WP 5.6.2 and PHP 7.4 on a web host