The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Change Foot to Feet in a text field?

Labels

This Discussion is public

Notifications

I am creating a Certificate that will be sent as an attachment to the form email.  The certificate thanks people for donating square feet of a new bike trail.  I want the form to say they donated either "1 foot" or "20 feet" for example.  The number is no problem, it is a simple a numeric field I can add to the pdf.  The problem is that I need a text form field that changes from "foot" to "feet" based on the value of the number of feet.

Any thoughts on how this could be done?

Thanks,

Steve

probably several ways to do this and this one is probably the worst of the lot, but it's the first that came to mind and might at least get you started or give you some ideas... I'd probably stick something like this in the "after fields" section under customize html to set a hidden text field based on the calculated 'square feet sponsored' field.

if the editor here strips/mangles it, there's a quick sample form and page w/ it at: https://oneofmydomains.com/footorfeet/

<script type="text/javascript">
jQuery(document).ready(function($){
// my Form field keys are:
// Square feet sponsored: 54p4h
// Foot or feet: fycdf
// change yours in all places as appropriate...
//get the number of sq feet sponsored
$('#field_54p4h').change(function(){
var val1 = $("#field_54p4h").val();
//set the foot or feet based on the sponsored amount
//if sq.f. sponsored is equal to 1 set it to foot
if (val1 == 1)
{$("#field_fycdf").val('foot');}
//if sq.f. sponsored is larger than 1 set it to feet
else if (val1 > 1)
{$("#field_fycdf").val('feet');}
//make it so
$("#field_fycdf").change();
});
});
</script>

Wow, thanks for the very complete answer and working example wilkd.  I will play around with that method and see if I can get it to work.  Thanks very much for taking the time to do this for me.

Steve

@wilkd, echoing that: Pretty cool that you built out the whole js for this!

@Steve, I wanted to offer another possible approach, which maybe won't work at all depending on your needs? I'm not sure how you're getting the PDF to attach to the email. However, the way I'd go about this is I'd set up 2 read-only text fields on the form, one that says "foot" as the default value, the other "feet". Then, I'd put a conditional on each of them to display the "foot" one if your numeric field is equal to 1, and "feet" if not equal to 1 (since a value of 0 should still be "feet").

Would be cool to hear how you go with this. I'm gonna hang onto wilkd's javascript for future reference!

@esadmin  thanks, but it's not mine, it's a rip from this (very useful) KB page:
https://formidableforms.com/knowledgebase/javascript-examples/#kb-conditional-calculation

ooh, good point on the conditionals... might even not need js or a hidden field for it depending on how the pdf is being handled... in a view or email you could just do something like this

 

(line breaks added for readability)
Thanks for the $[fieldkey] donation.
We'll dedicate
[if 54p4h equals="1"] 1 square foot [/if 54p4h]
[if 54p4h not_equal="1"] [54p4h] square feet [/if 54p4h]
in your name blah blah blah

Thanks for the reply and suggestion esadmin.

Actually that is what I am currently doing when I display the certificate in the page after submit and in the body of the email sent to the donor.  Unfortunately I don't think that will work for the pdf attachment.  (I want to include a pdf attachment to make the certificate printable.)

I am using the Pro2PDF plugin to create the attachment and it does not have the ability to do conditionals. It only substitutes Formidable field values into a template pdf's form fields.  That's why I need to set the value to "Foot" or "Feet" in a single Formidable field.

Steve

Why don't you use the abbreviation 'ft.' this is the same for foot and feet.

Clever!  Hadn't thought of that.  Not as appealing from an aesthetic or technical point of view, but certainly simpler and more reliable.

Steve

Discussion closed.