• Resolved olbro

    (@olbro)


    Currently the list of prefixes is fixed and only available in English. Which means I can’t use it on the French version of my form. Is there a way to edit this list and/or replace the prefixes in it?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @olbro

    Hope you are doing fine!

    This request has been already shared with our developers and we’ve just put it on our improvements “to do” list. As for now, there’s a workaround that could work for you. It would require adding a small piece of code to the?site:

    <?php 
    
    function wpmu_forminator_customize_name_prefixes( $prefixes ) {
    	
    	/* customize existing prefixes; default are
    	
    			'Mr'   => __( 'Mr.', Forminator::DOMAIN ),
    			'Mrs'  => __( 'Mrs.', Forminator::DOMAIN ),
    			'Ms'   => __( 'Ms.', Forminator::DOMAIN ),
    			'Miss' => __( 'Miss', Forminator::DOMAIN ),
    			'Dr'   => __( 'Dr.', Forminator::DOMAIN ),
    			'Prof' => __( 'Prof.', Forminator::DOMAIN ),
    	
    	*/
    	
    	$prefixes['Mr'] = 'Herr';
    	
    	/* add new one */
    	$prefixes['Abc'] = 'ABC.';
    	$prefixes['Xyz'] = 'XYZ';
    	
    	
    	return $prefixes;
    	
    }
    
    add_action( 'forminator_name_prefixes', 'wpmu_forminator_customize_name_prefixes', 10, 1 );

    You can modify the code according to your needs. In the code above one of the prefixes has been changed as an example (“Mr” to “Herr”)?and also there is an example on how to add more. Feel free to customize the code based on the prefixes you need.

    To add the code to the site:

    1. Create an empty file with a .php extension (e.g. “forminator-customize-name-prefixes.php”)
    2. Copy and paste my code there
    3. Make necessary adjustments
    4. Upload the file to the “/wp-content/mu-plugins” folder of your site’s WP installation, via FTP or cPanel “File Manager”; if there’s no “/mu-plugins” folder right in “wp-content”, just create an empty one?first.

    Hope this information helps

    Kind regards

    Luis

    Thread Starter olbro

    (@olbro)

    This request has been already shared with our developers and we’ve just put it on our improvements “to do” list.

    Great, I’ll look forward to it ??

    As for now, there’s a workaround that could work for you. It would require adding a small piece of code to the site:

    I see one problem with that. The prefixes would be changed on all forms. But my site is bilingual (English & French), and I want each form to have its own prefixes (Mr. & Ms. for the English form; M. & Mme for the French one). Is it possible to make the code you suggested form specific?

    At the moment I’m using the “Select” field for choosing a prefix, but it doesn’t look good, the field is simply too large (example in English).

    • This reply was modified 1 year, 7 months ago by olbro. Reason: added question in the paragraph before last
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @olbro

    It would be possible to make it “form aware” with a bit extended code:

    <?php 
    
    //customization for EN form
    function wpmu_forminator_customize_name_prefixes_en( $prefixes ) {
    	
    	$prefixes['Mr'] = 'Herr';
    	
    	/* add new one */
    	$prefixes['Abc'] = 'EN 1.';
    	$prefixes['Xyz'] = 'EN 2';
    	
    	
    	return $prefixes;
    	
    }
    
    // customization for FR form
    function wpmu_forminator_customize_name_prefixes_fr( $prefixes ) {
    
    	
    	$prefixes['Mr'] = 'Herr';
    	
    	/* add new one */
    	$prefixes['Abc'] = 'FR 1.';
    	$prefixes['Xyz'] = 'FR 2';
    	
    	
    	return $prefixes;
    	
    }
    
    add_filter( 'forminator_cform_render_fields', 'wpmu_formiantor_customize_name_prefixes_trigger', 10, 2 );
    function wpmu_formiantor_customize_name_prefixes_trigger( $wrappers, $form_id ) {
    	
    	
    	// EN form 
    	if ( $form_id == 2527 ) {
    
    		add_action( 'forminator_name_prefixes', 'wpmu_forminator_customize_name_prefixes_en', 10, 1 );
    		
    	}
    	// FR form
    	if ( $form_id == 123 ) {
    		
    		add_action( 'forminator_name_prefixes', 'wpmu_forminator_customize_name_prefixes_fr', 10, 1 );
    		
    	}
    	
    	return $wrappers;
    	
    }
    
    	/* default prefixes, for reference
    	
    			'Mr'   => __( 'Mr.', Forminator::DOMAIN ),
    			'Mrs'  => __( 'Mrs.', Forminator::DOMAIN ),
    			'Ms'   => __( 'Ms.', Forminator::DOMAIN ),
    			'Miss' => __( 'Miss', Forminator::DOMAIN ),
    			'Dr'   => __( 'Dr.', Forminator::DOMAIN ),
    			'Prof' => __( 'Prof.', Forminator::DOMAIN ),
    	
    	*/

    The key points are:

    1. You can see that there are two functions with names starting with “wpmu_forminator_customize_name_prefixes_” – one ending with “en” and one with “fr”. Those wold be your “language specific” customizations;

    2. then in this parts of code

    // EN form 
    	if ( $form_id == 2527 ) {

    and

    // FR form
    	if ( $form_id == 123 ) {

    you just need to set correct form IDs for each form.

    It should work out of the box and you can also extend it to support more languages (it should be pretty self explanatory but if you need help with is, let us know).

    Best regards,
    Adam

    Thread Starter olbro

    (@olbro)

    Thank you for your help. I just tested the code locally and it works ??

    Except that now the dropdown lists contain both the items that I modified and all the others (mrs, miss, dr etc.) So I need to remove the items from the dropdown list that I don’t need. How can I do that?

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @olbro

    I’m not sure if you actually modified or added new ones but in general, you can remove any of existing ones by adding a line (one or multiple if you want to remove multiple) like this to each of the functions (just make sure it’s above the “return…” line):

    unset($prefixes["Mr"]); // to remove whatever is default for MR
    unset($prefixes["Dr."]); // to remove whatever is default of Dr. 

    and so on.

    Best regards,
    Adam

    Thread Starter olbro

    (@olbro)

    Thank you Adam ?? Right now, the code is like this:

    <?php 
    
    //customization for EN form
    function wpmu_forminator_customize_name_prefixes_en( $prefixes ) {
    	
    	$prefixes['Mr'] = 'Mr.';
    	$prefixes['Ms'] = 'Ms.';
    	unset($prefixes["Mrs"]);
    	unset($prefixes["Miss"]);
    	unset($prefixes["Dr"]);
    	unset($prefixes["Prof"]);
    	unset($prefixes["Mx"]);
    	
    	return $prefixes;
    	
    }
    
    // customization for FR form
    function wpmu_forminator_customize_name_prefixes_fr( $prefixes ) {
    
    	
    	$prefixes['Mr'] = 'M.';
    	$prefixes['Ms'] = 'Mme';
    	unset($prefixes["Mrs"]);
    	unset($prefixes["Miss"]);
    	unset($prefixes["Dr"]);
    	unset($prefixes["Prof"]);
    	unset($prefixes["Mx"]);
    	
    	return $prefixes;
    	
    }
    
    add_filter( 'forminator_cform_render_fields', 'wpmu_forminator_customize_name_prefixes_trigger', 10, 2 );
    function wpmu_forminator_customize_name_prefixes_trigger( $wrappers, $form_id ) {
    	
    	
    	// EN form 
    	if ( $form_id == 1019 ) {
    
    		add_action( 'forminator_name_prefixes', 'wpmu_forminator_customize_name_prefixes_en', 10, 1 );
    		
    	}
    	// FR form
    	if ( $form_id == 651 ) {
    		
    		add_action( 'forminator_name_prefixes', 'wpmu_forminator_customize_name_prefixes_fr', 10, 1 );
    		
    	}
    	
    	return $wrappers;
    	
    }

    (there was a typo in the code above, “formiantor” instead of “forminator”; there’s also another default prefix called “Mx” which I also wanted to exclude)

    Now for both forms I have only two choices, which is what I wanted ?? Thank you again ??

    This is of less importance, but is there a way:

    • to make the prefix field a required field?;
    • to show the field blank until people have selected either Mr or Ms?
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @olbro

    Thanks for response and sorry for the typo, I’m glad you noticed it!

    As for your questions:

    to make the prefix field a required field?;

    No, not really. You can make entire name field required and this would make “some” prefix included in it any way – we can’t check, however, if the correct one was selected. If you add an “empty” one, it would also allow it.

    to show the field blank until people have selected either Mr or Ms?

    You can add a line like this in both functions

    $prefixes['Nn'] = '&nbsp;';

    Best regards,
    Adam

    Thread Starter olbro

    (@olbro)

    Thank you Adam. I will leave as it is then, if the field is not required then I won’t add a blank field, otherwise people might leave it blank. And my purpose was to know people’s gender without asking them directly and without having to guess with their name.

    Thank you again to you and Luis for the clear and precise assistance ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Modify the list of prefixes in Name field’ is closed to new replies.