Skip Navigation

[Resolved] Help with form

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user wanted to use Toolset Maps in forms and store the geodata in separate fields(geo_latitude, geo_longitude).

Solution:
Toolset Maps offers the location field which stores both latitude and longitude in the same field.
To be able to split the value into two fields, we need custom code. In this ticket, we created a custom code in Javascript that will populate the fields geo_latitude and geo_longitude and we made the field hidden on the form.

Relevant Documentation:

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+00:00)

This topic contains 11 replies, has 2 voices.

Last updated by frankW 3 years, 11 months ago.

Assisted by: Jamal.

Author
Posts
#1561971

Hi there,
how can I process the coordinates of my location in a form, save it in the fields geo_latitude and geo_longitude and upload it to my frontend using the form.

Kind regards

#1562531

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

I am not really sure to understand your request, but I'll try to give some insights on how to use maps with Toolset plugins.

Toolset Maps offers the possibility to integrate with Google and Azure Maps API. You can create an address field on your custom post type and then use it inside your form.
Check this articles
=> https://toolset.com/documentation/user-guides/maps/how-address-fields-work-in-cred-forms/
=>https://toolset.com/documentation/user-guides/custom-content/using-custom-fields/#how-to-add-custom-fields-to-content

When you create the Address field after installing the Toolset Maps plugin, the address field will hold the address but using this field you can also display the saved address latitude and longitude. You do not require two custom fields.

Can you please check and see if the Address field offered by map plugin is enough for you?

If you want to store each information on its own field, you will have to add a custom code to do so. Either you can do it on the frontend with a Javascript code, check this forum ticket which is similar https://toolset.com/forums/topic/latitude-longitude-fields-2/#post-1362093

Or you can hook into the save_post hook, pull latitude and longitude from the address field and store it on each field. Keep in mind that Toolset custom fields are prefixed with 'wpcf'. You will need to use this code:

update_post_meta( $post_id, 'wpcf-field-name', $value);

Instead of this code:

update_post_meta( $post_id, 'field-name', $value);

I hope this answers your question! Let me know if you have any doubts.

#1563567

Hello,
there is a problem with the further processing of my form in Cred. I can't activate the "Current visitor's location" option when I insert the marker. The error message is: "Your page is running on insecure HTTP, so you cannot get the location of the visitors".
But this is not correct because my website and the admin of my website run under https. Is there an error in Cred?

Kind regards

#1564115

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hi,

Please make sure you follow the steps on this article https://toolset.com/documentation/user-guides/maps/how-address-fields-work-in-cred-forms/#selecting-use-my-location

If your website is on HTTPS, it should work, maybe there is a compatibility issue with another component of the website, please check if this issue appears when:
- Only Toolset plugins are activated. It will tell us if there is an interaction issue with another plugin.
- The theme is set to a WordPress default like Twenty Fourteen. It will tell us if there is an interaction issue with your theme.
If the problem disappears, start activating one at the time to track where the incompatibility is produced.

Can you test on another browser, maybe you have denied access to your location to your website.

If this does not help, I'll need to take a closer look to your form, can you allow me temporary access(WordPress/FTP) to your website?
*** Please make a FULL BACKUP of your database and website.***
Your next reply will be private to share credentials safely.

#1565335

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Thank you for the access information. I confirm they are working for me.

I changed the user language to English because I don't know Deutsch. Then I found that you are using two text fields as "geo_latitude" and "geo_longitude" on your post fields group, then you are using a map on your form. Unfortunately, this will not work.
I suggest one of the following solutions:
1. Without Toolset Maps
You can keep your existing structure, then remove the map from the form and use one of the solutions described here hidden link

2. Using Toolset Maps
You will need to add an address field in your fields group. Then add an address field in the form. Then you will need to use a custom code (Either Javascript, or PHP) to split the coordinates from the address field into the geo_latitude and geo_longitude fields.
Please note, that when you add an address field to your form, the form will show an input text before the map, where the user should enter the address, or he can use the "Use my current location" button. This will only populate the address field. Then, as mentioned, in my first reply, you will need a custom PHP or Javascript code to populate "geo_latitue" and "geo_longitude".
This is an example of using Javascript code https://toolset.com/forums/topic/latitude-longitude-fields-2/#post-1362093

For PHP code you can use the cred_before_save_data API to pull the address value and split it into your fields.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

Please let me know if this helps.

#1565353

Hello Jamal,
thank you for your message. Could you implement your suggestion 2 (with a great card) for me?
Thank you very much.

Kind regards

#1565843

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello,

I already added an address field to your custom fields and to the form. I also added the following code to your form that checks if the address input has been populated from the map and then it populates geo_latitude and geo_longitude.

jQuery(function($){
    // cache selectors
    var address = $('input[name=wpcf-address]'),
        latitude = $('input[name=geo_latitude]'),
        longitude = $('input[name=geo_longitude]');
    // perform a check each 300ms
    setInterval(function(){
      var val = address.val()
      if (val) {
        var coords = val.replace('{', '').replace('}', '').split(',');
        latitude.val(coords[0]);
        longitude.val(coords[1]);
      }
    }, 300);
});

I am sure, you will understand, that as Toolset supporters, we are meant to assist you and give you guidance on how to build Toolset website and with any bugs you may encounter. But it is not our duty to build your website for you. If you are not comfortable with coding, I suggest hiring one of our partners https://toolset.com/contractors/

Best regards,
Jamal

#1568385

Hello Jamal,
I thank you very much for your help. It is not my intention to have support build my website. You will also understand that not every user can create a custom code and therefore needs some help. OnTheGo Systems advertises that can be created with toolset websites without any code knowledge.

The documentation of Toolset cannot always be understood in translation.

Thanks to your help, my problem is solved. Thank you so much!

I have two questions about the toolset form:

1. Why can't I select and upload images from the Worpress media library in the responsive design of my topic? This is possible in the desktop version of my theme.

2. Can I load the block editor into my frontend using the toolset form?

Kind regards

New threads created by Jamal and linked to this one are listed below:

https://toolset.com/forums/topic/media-library-on-small-devices/

#1569229

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Frank and thank you for your feedback. I do understand that the documentation may not always be enough, and we, at the support forum, will do our best to help.

For your last questions, I have created another ticket to answer them. For support rules, we are able to handle only one issue at the time. This helps us to bring you a better service and also helps other users to find all the information here exposed.

As the initial issue of this ticket is corrected, I'll kindly ask you to mark this ticket as resolved.

#1574743

Hello Jamal,

I have two more questions about the problem.
1. As I see, inserting the address field generates 2 additional fields (latitude and longitude). Could I continue to use these two fields and edit them instead of my two fields geo_latitude and geo_longitude?

2. Would there be a possibility to select and upload a location on the map in the form instead of my exact position? Or can you offer several "next addresses"?

3. How can I show the address of the generated location in addition to the coordinates in the uploaded contributions via the form?

Kind regards

#1577077

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Frank and my apologies for the late reply, but I do not work on Mondays.

1. The location field does display two additional fields for latitude and longitude on the form but then stores the value on a single field as "{lat_value,long_value}". If you need to store the latitude and longitude each one on each own field, you will still a logic on the server-side(PHP) or on the client-side(Javascript) to populate the fields.
I suggested a Javascript solution in my reply https://toolset.com/forums/topic/help-with-form/#post-1565843
You may want to hide your latitude/longitude fields on the form so they do not appear, but they still get populated with the Javascript solution before posting.

2. I did not understand what would you mean by Or can you offer several "next addresses"?
The location field offers:
- An address input to choose an address autocompleted by the maps API, where you can choose an address and the API will position the marker on it and pull the latitude/longitude.
- "Use my current location" button, which will use the maps API to position the marker on your location and pull the latitude/longitude.
- The marker on the map can be dragged and the latitude/longitude will be updated.

3. I did not understand this question very well, can you elaborate more on this question, I would prefer that you create a new ticket for it, if it is not related to the form page.

#1584325

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.