Forum OpenACS Development: Invalid input syntax for integer

Collapse
Posted by Iuri Sampaio on
Hi there,

What would be the best solution to the error bellow?

I may create datatype validation as follows:

1. To add Javascript independetly of acs_template

2. To add -validate block in the ad_page_contract statement

3. To add -validate block in the ad_form template

4. What else is abvailable?

Best wishes,
Iuri

[12/Dec/2017:10:49:45][1890.7f23de866700][-conn:evex:0-] Notice: Add Item
[12/Dec/2017:10:49:45][1890.7f23de866700][-conn:evex:0-] Error: nsdbpg: result status: 7 message: ERROR: invalid input syntax for integer: "dfwfveqrwcv"
LINE 18: 'dfwfveqrwcv'
^

Collapse
Posted by Antonio Pisano on
I would say not much else... Javascript validation makes sense in order to avoid useless requests to the server, but some server-side validation you should do anyway to prevent garbage to be entered. Whether you want to do it at the page_contract or in the form depends on your application and I cannot really comment

Hope this helps

Ciao

Collapse
Posted by Iuri Sampaio on
A good solution can be achieved by simply changing ad_form's element to element_1:integer(text).
That way, validation comes within the acs-template pkg.

This option would even reduce the amount of code within ad_form -on_submit, or ad_page_contract blocks.

Nevertheless, I wonder what would be necessary if I'd chosen JavaScript instead, separated from acs-template,

Best wishes,
Iuri

Collapse
Posted by Gustaf Neumann on
The proper way for HTML5 is to use an "input" field with type "number" and an integer "step", maybe a "min"/"max" value [1]. The HTML5 input types with their attributes are supported by the xowiki form fields, which are not integrated (yet) with ad_forms.

For the ad_page_contract, you do not necessarily have to have a validate block, but you should use in the "argspec" the type "integer "(or "naturalnum", etc.) [2]. The validate block is just needed for detailed checks (check for certain integers, checks against the db, etc.)

[1] https://www.wufoo.com/html5/types/7-number.html
[2] https://openacs.org/api-doc/proc-view?proc=ad_page_contract&source_p=1

Collapse
Posted by Iuri Sampaio on
Thanks! Nice reference, btw. I didn't know Wufoo.com