Skip Navigation

[Resolved] Populate CRED european decimal format price to numeric custom field

This support ticket is created 7 years, 3 months 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 9 replies, has 3 voices.

Last updated by Beda 7 years, 3 months ago.

Assisted by: Beda.

Author
Posts
#482027

PLI

I am trying to: populate an european formatted price (2,45) to a numeric custom field (2.45) with cred

I visited this URL:

I expected to see:

Instead, I got:

#482231

Comma separated value is not allowed in the Types Number Field if used in the Post Backend edit screen.

As such it's also not allowed in the front end.
There is no method to unset that.

What you can do is use a Single Line Field, where any form of input is allowed.

#482430

PLI

Thanks for your Feedback. European prices are different formatted (100,00 instead of 100.00). How can i store these prices in a custom field with sorting output options and a limited numeric input without characters?

#482944

PLI

Keine Lösung Beda? Es muss doch möglich sein europäische Preisangaben als numerischen Wert in CRED abzufragen. Bei einem single Line Feld kann ja auch Text dahinter eingegeben werden und die Eingabe kann dann bei der Ausgabe z.B nicht nach < oder > durchsucht werden.

#483175

Nein, dies ist leider nicht möglich mit dem Nummern Feld.

Was Du tun könntest ist ein "Single Line" Feld zu verwenden und dann eine "Validation" zu verwenden wie hier erklärt:
https://toolset.com/documentation/user-guides/cred-api/#cfv

Damit könntest Du beim einsended der Form nach dem Feld Inhalt suchen und überprüfen dass nur Nummern eingegeben werden.

Ich kann die Entwickler fragen diese option zum Types "Nummern Feld" hinzu-zufügen, wenn Du dies möchtest?

#483262

PLI

Hallo Beda,

danke für Deine Antwort. Ich denke das ein "Single Line" Feld keine gute Lösung ist.

Man könnte das vorhandene Numeric Field um eine Option (0.00 oder 0,00) erweitern, ich denke das wäre für einen business Einsatz im europäischen Markt zwingend notwendig - sonst kann man ja keine Preise in der Datenbank sinnvoll speichern. Deshalb möchte ich hiermit einen Feature Request dafür stellen.

Bevor ich ein single line Feld umsetze würde ich lieber warten ob es eine Umsetzung geben wird und mit welcher Priorität?

#483521

Dies macht sinn.

Ich werde diesen Thread an Juan zuweisen, unser Lead Developer.
Er spricht kein detusch, somit wird er auf English antwerten.

Für den moment, ist die verifizierung des TEXT feldes die einzige möglichkeit um dieses Ziel zu erreichen.

#483728

Juan
Supporter

Timezone: Europe/Madrid (GMT+02:00)

Hi there

Thanks for the feedback.

This has been requested a number of times already, and we all agree that this makes a lot of sense. We really want to have this. But there are some problems we need to face before that.

Other plugins allowing for custom separator characters do so by duplicating the field: it is stored once with whatever separator, and a hidden instance holds the natural, dot separator value. We would like to avoid that.

We were thinking about a filtering on-the-fly. The stored value would always be dot separated, but then upon display it would show whatever character you decide. However, it is not clear how to make it work properly with, say Views filters where you will certainly use the non-dot character, for example. The setting has to be consistent, no matter which Toolset product is involved with the field.

As you can see, we need to cover lots o effects on such a change. So even if we do want this included, that we do, we need to have a clear and complete solution before making it available to everyone to use. We do not want to half bake this and get you here again asking why this is broken so soon 🙂

Hope it helps.

Regards.

#484015

PLI

Hi Juan,

thanks for your reply. I will then wait for your solution and use a textfield in the meantime.

Can you please provide a CRED php snippet for use as workaround for prices with textfield and verification, whether the entered value is in the correct (0,00) format without any other character etc.? That would be great 🙂

Thanks

#484019

This is Beda again; I took back the ticket as the feature request is answered and your last query is related to Support/Usage of Toolset.

So to validate a Field in your CRED form you will use the CRED API and PHP.
We provide a Hook (CRED API) that makes sure your Custom Code (PHP or WordPress API) that you code IN the hook will get fired at the correct moment.
Strictly speaking, everything INSIDE the hook is custom code, and these Rules apply:
https://toolset.com/toolset-support-policy/

But I will give you below the information how you can achieve this code and can help review the code you craft if you need.

1. Use this CRED hook:
https://toolset.com/documentation/user-guides/cred-api/#cfv

2. Inside that hook you will address the Single Line Field with:

$fields['wpcf-my_field']//replace my_field with your filed's slug

This is an array, containing:

'value'=> actual field value,
'name'=> field name, 
'type'=> field type (eg email, file, image, text etc..),
'repetitive'=> whether this field is repetitive or not

You will of course address the "value".

3. To validate the value you can use the PHP function preg_match() to check if the string of the field contains any character but numbers, dots and commas.
http://stackoverflow.com/questions/26523915/how-can-i-accept-only-letter-number-comma-and-dot-using-php

4. Then you compare the field as shown on our API Doc against the preg_match regex value.

5. Another approach can be to use preg_replace()
This allows you to check the string and directly replace/remove any character of your choice and directly submit the Form content without any error message.
http://stackoverflow.com/questions/4949279/remove-non-numeric-characters-exlcuding-periods-and-commas-from-a-string
hidden link

This last one could even be done on the cred_save_data() action because you don't need to validate, you simply replace what's submitted and do not need to notify the user about any errors.

Please let me know what you choose, and if you need some help of reviewing the code.

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