Skip Navigation

[Resolved] format user input

This support ticket is created 6 years, 7 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
- 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)

This topic contains 7 replies, has 2 voices.

Last updated by Luo Yang 6 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#572414

Hi Luo ,

Pls look into this tutorial link :
hidden link

i would like to implement this for my search form fields , the field are property-price and property-size.
I am not sure how to add this functions, can you guide me along please.

i will try on my end too.

thank you.

#572451

Dear C6410,

I assume you are going to format the user input number with comma, for example "12,456", the link you provided is a JS solution, which works in front-end, it will be able to turn the numeric value "12345" into string value "12,456", but it will pass URL parameter as string value to Views in server side, so it will conduct unexpected problem, for example, in your website:
without comma, just numeric value 12345
hidden link

and with comma, string value 12,345
hidden link
There are other unexpected results.

So it is not recommended to use the scripts you mentioned above.

#572455

Hi. I understand this issue .

Do you have other way to achieve this ? Thanks.

#572464

There should be other workaround, for example when user submit the form, and pass URL parameter with string value "12,345" to Views, you can try with Views filter hook wpv_filter_query to trigger a custom PHP function. in this PHP function do these:
1) Get the string value, and remove the comma, turn it into numeric value
2) pass it to Views query
See our document
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.

But since it is not the built-in feature of Views plugin, it will make things complicated, only for your reference.

#573248

Thanks for the details. does this extra code increase server resources ?

appreciate if there is any sample code ,meanwhile ill try something my end too. thank you.

#573471

Q1) does this extra code increase server resources ?
The extra code will spend some server resources, but it should not conduct performance problem.

Q2) if there is any sample code
In the document:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
click link "Usage examples", you will be able to see the example codes of how to use filter hook "wpv_filter_query"

#573487

Ok, thanks. ill try and update you the code soon. cheers

#573619

OK, please update this thread if you need more assistance for it. thanks

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