I have a form which has two input fields. In my server action I’m using the Database Insert and I want one of the fields to be the two posted form fields added together, eg.
{{$_POST.field1}}+{{$_POST.field2}}
It seems to be storing the value in $_POST.field1 and ignoring the rest.
How should I be doing this?
{{$_POST.field1 + $_POST.field2}}
2 Likes
Thanks @s.alpaslan . I’d already tried that and it didn’t make any difference.
Just to be clear, field1 and field2 contain numbers and I want to add them together and store the total.
Can you share screen shot with us ? Maybe you have different issue
No problem. I can see that it should work as it’s showing as an operation (see screenshot).
I’m on the very latest version in case that’s relevant.
George
January 13, 2019, 8:21pm
6
All Global input variables are strings initially. So if you want to do math - you have to convert them to numeric first
so in your case it will result in something like {{$_POST.field1.toNumber() + $_POST.field2.toNumber()}}
1 Like
George
January 13, 2019, 8:24pm
7
Also if you expect them to be numeric, always define them with validation:
So a nice validation error is reported if somehow a different type of field is passed - and not some weird database error when you try to store them.
Yesssss!!! Perfect. That was the step I was missing. Converting to number fixes it.
Huge thanks to both of you.
1 Like