How to add a comma to numbers in a shortcode

By: Mark Hansen | Asked: 12/11/2023
ForumsCategory: General questionsHow to add a comma to numbers in a shortcode
Mark HansenMark Hansen asked 8 months ago
Hi All - Thanks in advance for any guidance. I'm using the paragraph field to display a confirmation message to the user before the form is completed. I'm using the FP shortcodes to pull in the information they submit into the fields and displaying a paragraph. 

Ex: User states they need 160l x 280w feet of something. I calculate the square footage and it's part of the confirmation message. 

Ex message: Thanks [fname], please confirm that you need 160L x 289W, or [sqft] of the thing you need.

Problem: The [sqft] shows as a single string, ie: 44800 - I have tried using the [XX thousands_sep=","] and it simply shows the shortcode instead of the value with a comma separator ex: 44,800. 

Is there a way to get this to display the properly format number in a paragraph field? (It does not work in an html field either)

Thanks,
Mark
1 Answers
Rob LeVineRob LeVine answered 8 months ago
Since the form hasn't been submitted at the data isn't associated with an entry, the only way I can think of to accomplish this is jQuery. In your confirmation message, you have some placeholder element (e.g., span) and use jQuery to "do the math" and put that text into the span.
Mark HansenMark Hansen replied 8 months ago

Thanks, Rob. I'm trying to get away with not having the user submit the form at all - it's really a basic calculator and nothing more, so it shows the user the result on the same page and will not likely have any submit function at all.

I'll try to find a workaround.

Much appreciated input.

Rob LeVineRob LeVine replied 8 months ago

The only thing I can think of outside of jQuery (which isn't hard, but that's easy for me to say if you don't know jQuery) is to have some awkward-looking fields that cozy up next to each other and look like they belong that way. i.e., You have an HTML field with the text "Thanks " and next to it as close as possible put a text field with a calculation using the field ID of the first name, and then another HTML field with "please confirm that you need" and so on and so on. It might be a CSS nightmare, but it might work.

Mark HansenMark Hansen replied 8 months ago

As-is, it's really not too bad, it just doesn't look as perfect as I'd prefer. Haha. What's odd, is that the [XX thousands_sep=","] doesn't work on any type of field when you create a basic calculator. It MAY work after it's been submit, but that somewhat defeats the entire purpose.

Thanks again,
Mark

Victor Font replied 8 months ago

Here's an old article I wrote about formatting fields as currency. This will work for your challenge. https://formidable-masterminds.com/formatting-fields-as-currency/

Mark HansenMark Hansen replied 8 months ago

Thanks, Victor! I believe I've actually used this before (doh!) and completely forgot about it. Age is starting to reach out and remind me of things.

Much appreciated!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right