• Resolved follaky

    (@follaky)


    Hi!

    I have a request similar to the following topic:

    https://www.ads-software.com/support/topic/generate-post-title-from-another-field/

    I tried to adapt the code from the link in the question. However, I wasn’t able to make it work.

    Let me explain in more detail:

    I have a custom post type and I use a Forminator form to gather information about the customer and populate fields in the post. The post generation works nicely, however I’m always forced to use either Title or Content in order to be able to pass on meta values to the post. Since the custom post has it’s own title field, I had to “mask” the Post Data Title field as being for “administrative use” and have the customer write two titles for their entry.

    Following the example from the link above, I created a code snippet to replace the title with the value of {text-1}.

    <?php
    add_action( 'wp_footer', function(){ ?>
    <script type="text/javascript">
    
    jQuery( document ).ready(function($)
    
    {
    
    $("#postdata-1-post-title").prop("readonly", true);
    
    
    
    $('#text-1-field').change(function()
    
    {
    
    var title = jQuery('#text-1-field').val();
    
    jQuery("#postdata-1-post-title").val(title);});
    
    });
    
    </script>
    <?php } );

    Unfortunately, this doesn’t work and I couldn’t find a way to adapt the solution proposed by Patrick Freitas to be used as a code snippet.

    Thanks in advance for helping.

    Best

    Olivier

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @follaky

    I hope you are doing well.

    We updated the field IDs so we also need to update the code a bit, can you try this version?

    <?php
    
    add_action( 'wp_footer', 'wpmudev_radio_field_auto_selection', 9999 );
    function wpmudev_radio_field_auto_selection() {
    	global $post;
    	if ( is_a( $post, 'WP_Post' ) && !has_shortcode( $post->post_content, 'forminator_form' ) ) {
            return;
        }
    	?>
    	<script type="text/javascript">
    	jQuery(document).ready(function($) {
    		setTimeout(function() {
    			$('.forminator-custom-form').trigger('after.load.forminator');
    		}, 1000);
    
    		$(document).on('after.load.forminator', function(event, form_id) {
    			if ( event.target.id == 'forminator-module-433' ) {
    				let _title = $('input[name="postdata-1-post-title"]');
    				_title.prop("readonly", true);
    
    				let _text = $('input[name="text-1"]');
    
    				$(_text).on("input", function() {
    					_title.val( $(this).val() );
    				});
    			}
    		});
    	});
    	</script>
    	<?php
    }

    Please update the forminator-module-433 and replace the 433 to your form ID https://monosnap.com/file/JgPeElH29MBWMI9BjWErx7ibPgx9ui

    Best Regards
    Patrick Freitas

    Thread Starter follaky

    (@follaky)

    Hi @wpmudevsupport12

    Thanks for the code! What’s shown in your example is exactly what I’d need. I tried to add a snippet with the code provided (changing the ID to match my form), but it doesn’t seem to work:

    Forminator Post Title from Text Field

    As you can see, the text from {text-1} isn’t copied over to the post title. However, the new post is created as expected, I’m getting mail notifications and so on.

    Am I missing an important point?

    Thanks again!

    Olivier

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @follaky

    Thanks for response!

    I just tested this code on my own test site and it worked perfectly fine out of the box.

    However, I tested it on a simple setup – with no other plugins active, a basic theme and very simple form. As far as I can see, your form is a bit more complex than mine and also a theme or other plugins (or even some JS optimization tools) may be coming in a way.

    Could you check if you are getting any JS errors in browser console (“Ctrl + Shift + J” on Windows and “Cmd + Option + J” if you’re on Mac) when filling-in the form and if yes – let us know what are they?

    Also, could you export the form itself and share it with us so we could test it?

    To export the form:

    – go to “Forminator -> Forms” page
    – click on a little “gear” icon next to the form in question
    – select “Export” options form the drop-down menu
    – copy export code and put it on pastebin.com or your Google Drive/Dropbox/similar
    – share direct (publicly accessible) link to it in response here.

    Note: form export code will only contain form itself – will not include any submitted data (which we don’t need either).

    Best regards,
    Adam

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @follaky ,

    We haven’t heard from you for over 2 weeks now, so it looks like you no longer need our assistance.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

    Thread Starter follaky

    (@follaky)

    Hi!

    Sorry for delayed reply.

    The problem was caused from a conflict with my page builder (Nicepage in my specific case). I had to modify the code like this and hope it isn’t unsafe to do it that way:

    add_action( 'wp_footer', 'wpmudev_radio_field_auto_selection', 9999 );
    function wpmudev_radio_field_auto_selection() {
        global $post;
        if ( is_a( $post, 'WP_Post' ) && !has_shortcode( $post->post_content, 'forminator_form' ) ) {
            return;
        }
        ?>
        <script type="text/javascript">
        (function($) {
            $.noConflict();
            $(document).ready(function() {
                setTimeout(function() {
                    $('.forminator-custom-form').trigger('after.load.forminator');
                }, 1000);
    
                $(document).on('after.load.forminator', function(event, form_id) {
                    if ( event.target.id == 'forminator-module-XXX' ) {
                        let _title = $('input[name="postdata-1-post-title"]');
                        _title.prop("readonly", true);
    
                        let _text = $('input[name="text-1"]');
    
                        $(_text).on("input", function() {
                            _title.val( $(this).val() );
                        });
                    }
                });
            });
        })(jQuery);
        </script>
        <?php
    }
    

    Maybe this can help other people facing a similar issue.

    Cheers

    Olivier

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @follaky

    Thanks for updating us!

    I think it should be fine as the data saved by the plugin is sanitized anyway.

    Best regards,
    Adam

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Post Data Title: generate from other field’ is closed to new replies.