Skip Navigation

[Resolved] controling a file donwload using a custom field

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

Problem:

Can I access a Customer Fields using JavaScript, and if yes, then how to I identify the custom field in the my code?

Solution:

You can setup your custom JS codes insider post content, like this:

https://toolset.com/forums/topic/controling-a-file-donwload-using-a-custom-field/#post-1189328

Relevant Documentation:

This support ticket is created 6 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: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by gavinJ-2 5 years, 12 months ago.

Assisted by: Luo Yang.

Author
Posts
#1187443

Hi -

I'm using a Custom Post Type for descriptions of my products. Each Custom Post Type record contains custom fields. One of these custom fields is a URL of a zip file download of that product (stored in my WordPress media library). I'm using Toolset for my Custom Post Types and Custom Fields. Is there any way for me to require users to provide their name and email address prior to showing them a button for doing the download. I'm guessing that I would need to create a View with some Javascript.

Another approach would be to use a forms plugin like Gravity Forms or Ninja Forms to do this. Are there any forms plugins that integrate with your Custom Fields?

#1187926

Hello,

There isn't such a built-in feature within Toolset plugins, I suggest you check if current user is a logged-in user:
- if it is a logged-in user, then you can get their name and email address, and display the file URL
- if it is a guest, then display a login URL

For example, use access shortcode [toolset_access] to check the user's role, and display different contents:
https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/
Access Control for Contents Inside Page Content

#1189004

Hi Luo -
This isn't really what I'm looking for. I think that I will need to have a developer write some custom code. But I do have a basic question about creating custom code. Here is the scenario ...
1. I build Custom Fields to store a customers name, email, phone, and URL of their website.
2. I build a Custom Post Type that uses these Customer Fields
3. I built a Template in Elementor to display the Custom Post Types
I think that it is possible to add JS code to the Elementor template to make the functionality that I'm looking for. What I need to know is how to access the Custom Fields values (name, email, phone, and URL ) stortedin the Custom Post Type.
Can you point me to any documentation and/or JS code examples?

#1189328

In front-end, within the single post content, you can use Types shortcode to display the field value, for example:
[types field="my-email" ouput="raw"][/types]

see our document:
https://toolset.com/documentation/customizing-sites-using-php/functions/

And there is Toolset form plugin, you can download it here:
https://toolset.com/download/toolset-cred/

Here is the document about Toolset form plugin:
https://toolset.com/documentation/user-guides/front-end-forms/

For your reference.

#1191479

This doesn't answer my questions. Can I access a Customer Fields using JavaScript, and if yes, then how to I identify the custom field in the my code?

#1191748

For example, you can setup your custom JS codes insider post content, like this:

<script type="text/javascript">
var my_var = '[types field='my-field' output='raw'][/types]';
console.log(my_var);
</script>

Test it in front-end, you should be able to see the JS variable outputted in your browser console window.

See our document:
https://toolset.com/documentation/customizing-sites-using-php/functions/

#1192026

My issue is resolved now. Thank you!