[Skip to main content](#vessel-content)

#   validation check on custom field

##

- **[RCarey](/forum/user/16089-rcarey "View RCarey's Profile")**
- [![RCarey's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/16089-rcarey "View RCarey's Profile") Topic Author
- [ Offline](/forum/user/16089-rcarey)

Less More

- Posts: 8
- Thank you received: 2
-
-

13 years 6 months ago [\#100883](#100883) by [RCarey](/forum/user/16089-rcarey "View RCarey's Profile")  *[validation check on custom field](/forum/4-how-to/80934-validation-check-on-custom-field#100883 "I am using a custom field and the donation plugin to create a gift card product where the site visitor can enter the amount to put on the card. One problem stumbled upon is that the user can enter...")* was created by *[RCarey](/forum/user/16089-rcarey "View RCarey's Profile")*

I am using a custom field and the donation plugin to create a gift card product where the site visitor can enter the amount to put on the card. One problem stumbled upon is that the user can enter something other than a digit or decimal. I would like to add validation to require a valid numerical value, or a way to process the input so as to strip out any non-numeric character.

Is this a setting I can make? If not, do you have a suggestion where in the code I can add this extra check?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgwOTM0LXZhbGlkYXRpb24tY2hlY2stb24tY3VzdG9tLWZpZWxkP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

13 years 6 months ago [\#101135](#101135) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[validation check on custom field](/forum/4-how-to/80934-validation-check-on-custom-field#101135 "I am using a custom field and the donation plugin to create a gift card product where the site visitor can enter the amount to put on the card. One problem stumbled upon is that the user can enter...")*

Hi,

If you want to do some verification in you custom field value, you'll have to do it through the custom_price.php file of your Hikashop custom price plugin by editing these lines : Code:

if(!empty($product-&gt;amount)){ foreach($product-&gt;prices as $k =&gt; $price){ $product-&gt;prices[$k]-&gt;price_value = $product-&gt;amount; $product-&gt;prices[$k]-&gt;price_value_with_tax = $product-&gt;amount; }

and these lines : Code:

if(!empty($product-&gt;amount)){ $product-&gt;order_product_price = $product-&gt;amount; $product-&gt;order_product_tax = 0; }

Hope this will help you a little.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgwOTM0LXZhbGlkYXRpb24tY2hlY2stb24tY3VzdG9tLWZpZWxkP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[RCarey](/forum/user/16089-rcarey "View RCarey's Profile")**
- [![RCarey's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/16089-rcarey "View RCarey's Profile") Topic Author
- [ Offline](/forum/user/16089-rcarey)

Less More

- Posts: 8
- Thank you received: 2
-
-

13 years 6 months ago [\#101157](#101157) by [RCarey](/forum/user/16089-rcarey "View RCarey's Profile")  Replied by *[RCarey](/forum/user/16089-rcarey "View RCarey's Profile")* on topic *[validation check on custom field](/forum/4-how-to/80934-validation-check-on-custom-field#101157 "I am using a custom field and the donation plugin to create a gift card product where the site visitor can enter the amount to put on the card. One problem stumbled upon is that the user can enter...")*

Thanks.

Yesterday, I found a way to add client-side validation as control leaves the field. Briefly, here's how I did that...

In the view files, for front-end products, I edited *show\_block\_custom\_item.php*. At the top of this file I added an implementation of the javascript function that would perform the validation. This function receives a value, performs validation, and then returns a valid form of the value. For my need, the user-entered text that had to represent a dollar amount. So the code stripped out all character except digits and a decimal. I was also able to add an alert box to inform the user if the amount was less than the minimum (and then reset the text to the minimum). This function's name was *forceToNumber(text)*.

Then, about 20 lines into the code, where the javascript function *hikashopToggleFields()* is inserted, I insert a call to my function just before that call to *hikashopToggleFields()*. Here is the completed line of code with my addition in bold:

> echo $this-&gt;fieldsClass-&gt;display($oneExtraField,$itemData,'data\[item\]',false,' '.$onWhat.'="**this.value=forceToNumber(this.value);**hikashopToggleFields(this.value,\\''.$fieldName.'\\',\\'item\\',0);"');

So in short, my validation function preprocesses the value and corrects any invalid values just before the processing function is called upon this value.

I realize that because this is the only custom field I am using, a simple implementation like this works for me. Were I to be using multiple custom fields, then I would have to add a parameter that would pass the field's name (or type) and then perform the appropriate validation per field name/type.

The following user(s) said Thank You: [nicolas](/forum/user/63-nicolas "View nicolas's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgwOTM0LXZhbGlkYXRpb24tY2hlY2stb24tY3VzdG9tLWZpZWxkP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.100 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
