Skip Navigation

[Resolved] Customise the placeholder text for Maps fields on a Post Form?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 29 replies, has 2 voices.

Last updated by Minesh 11 months ago.

Assisted by: Minesh.

Author
Posts
#2669617
Screenshot 2023-11-30 at 11.42.21.png

Hi Support

Is it possible to customise the placeholder text for Google Maps entry fields on a Post Form?

At the moment it always appears as "Enter address". I would like to change this to something like "Enter your approximate location".

I found lots of posts on the forum for customising the location placeholder text in Filters in Views, but not for Post Forms. I also tried:

[cred_field field='nanny-approximate-location' placeholder='my custom text' force_type='field' class='form-control' output='bootstrap']

in the Post Form, but "Enter Address" still appears. I suspect that "Enter Address" is somehow hardcoded in the Toolset Maps plugin.

I'm trying this in "Post Form - New Nanny Ad - Unverified Nanny", if you want to examine what I've tried...

Any ideas?

Thanks and kind regards
Simon

#2669675

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There is no such feature to override the placehoder text for the address field added to your form.

But here is the workaround mentioned with the following ticket that might be helpful to resolve your issue.
- https://toolset.com/forums/topic/placeholder-address-field-cred-not-working/#post-2323803

You can either use JS or gettext filter workaround.

#2669687

Hi Minesh

I tried the JS method, which worked fine in our primary language en, however when I sent the Post Forms for translation, the new strings didn't appear for translation into German (de).

Is there any way round this? Does the gettext method support WPML translation, and if so, how?

Thanks and kind regards
Simon

#2669703

Hi Minesh

By the way, in case it helps, this is what I did so far in JS:

var placeholder = jQuery("input[name*='wpcf-nanny-approximate-location']");
if( ! jQuery( placeholder ).val() ) { 
	jQuery( placeholder ).attr("placeholder", "Use postcode, area, or street eg 80801 Munich, Giesing, Bahnhofstraße");
};

EN
Use postcode, area, or street eg 80801 Munich, Giesing, Bahnhofstraße

DE
PLZ, Stadtteil oder Straße verwenden, z.B. 80801 München, Giesing, Bahnhofstraße

Thanks and kind regards
Simon

#2669783

HI Minesh

On a similar note, I'm also having trouble getting the placeholder text for a normal post title field translated via a Post Form. I tried all sorts of combinations with single and double quotes and [cred_i18n] tags but the editor can't seem to interpret it well.

[cred_field field='post_title' placeholder='[cred_i18n name='post_title-placeholder-text']eg Weekend nanny, French-speaking nanny, German tutor[/cred_i18n]' class='form-control' output='bootstrap']

Could you help me getting the syntax right?

Thanks and regards
Simon

#2669951

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What if you use the gettext filter as shown with the following reference ticket and try to translate the placeholder text:
- https://toolset.com/forums/topic/placeholder-address-field-cred-not-working/#post-2323803

You can adjust the gettext filter code as required for your title filed placeholder.

#2671113

HI Minesh

Sorry I may have confused you with the two related placeholder text translation issues:

1) Placeholder text one is the "Enter Address" for the Google Maps address entry field in a Post Form.

2) Placeholder text two is the translation of the standard option placeholder, as in [cred_field field='post_title' placeholder='THIS IS THE TEXT WE NEED TRANSLATED' ....

Perhaps we need to split this ticket into two issues so they can be handled separately?

Kind regards
Simon

#2672929

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry I may have confused you with the two related placeholder text translation issues:

1) Placeholder text one is the "Enter Address" for the Google Maps address entry field in a Post Form.
==>
This issue is already fixed - right?

#2672941

Hi Minesh

No, neither issue is fixed.

For the Google Maps address field issue, there may be no other solution than the proposed gettext.

The JS solution worked great in original language, but it not translatable, as Beda suggested, at least for me.

Beda mentioned that the gettext method is not good for performance. If it possible to solve either issue without adding custom code that would be best. Are you suggesting to use the gettext to solve both issues?

I suspect that the cred_field placeholder could be solved with the right syntax. My problem was placing a [cred_i18n] shortcode in the middle of the [cred_field] shortcode for the

placeholder='my custom text'

I think the PHP just has a problem misinterpreting the multiple single quotes, because placeholder= requires single quotes, but then so does the name argument of cred_i18n. I tried all sorts of combinations like putting the cred_i18n in double quotes etc, but without any luck. Maybe escape characters or similar could help?

Kind regards
Simon

#2672943

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share the link of the page where I can see the form where you added the address field and let me review what could be the best solution.

#2672945

Hi Minesh

Post Form - New Job Ad (ID: 929)

hidden link

There you can see:

[cred_field field='post_title' placeholder='eg Evening babysitter, English-speaking nanny, Spanish tutor' class='form-control' output='bootstrap']

and the code suggested by Beda for field family-approximate-location in the JS section.

Thanks and kind regards
Simon

#2672955

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Here is the custom Javascript code that will help you to get the current language code:

You should try to add the following code to yoru form's JS section.:

function get_current_lang_code_from_cookie(c_name) {
       var c_value = document.cookie,
           c_start = c_value.indexOf(" " + c_name + "=");
       if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
       if (c_start == -1) {
           c_value = null;
       } else {
           c_start = c_value.indexOf("=", c_start) + 1;
           var c_end = c_value.indexOf(";", c_start);
           if (c_end == -1) {
               c_end = c_value.length;
           }
           c_value = unescape(c_value.substring(c_start, c_end));
       }
       return c_value;
   }

current_lang_code = get_current_lang_code_from_cookie('wp-wpml_current_language');

if(current_lang_code == 'en'){
    /// add the JS code to replace the placeholder in English test
} else if  (current_lang_code == 'de') {
/// add the JS code to replace the placeholder in German test
}

I hope this will help you to fix the issue.

#2673099

HI Minesh

I'm sorry, I don't fully understand what you expect me to do - add this snippet to custom code and replace something where the comments are in lines 21 and 23?

Which issue is this aimed at fixing?

Unfortunately I have to go to hospital for 2-3 days so I may not be able to respond until Monday, but if I'm up and well, I can try to reply sooner.

Thanks and regards
Simon

#2674667

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please let me know once you back and we will continue here.

#2674993

HI Minesh

I'm already back and eagerly awaiting your further assistance 😉

Kind regards
Simon