Forums

Sending variable as data in a form

webbusteruk 23 Jan, 2019
Probably a pretty simple answer to this, but couldn't figure it out.

We've got a form in CCv6, where the user will enter values in multiple input boxes (ie L01, L02, L03, L04) within a form. We need to sum those values into one (ie M1) and send this as data within the same form.
$M1 = $L01 + $L02 + $L03 + $L04
How do we pass a variable (ie $M1) as input data in the form? Do we need to create a hidden input field (M1), but then how do we pass the variable $M1 into the field?
healyhatman 24 Jan, 2019
Any reason why you can't just accept the form inputs and sum them on submission? Any reason why you want them summed BEFORE submission?
webbusteruk 24 Jan, 2019
How do you sum them on submission?

Tried putting M1:{data:L01} + {data:L02} +... in the save data function but obviously it didn't work.
healyhatman 24 Jan, 2019
Answer
1 Likes
You can either rename the fields to L[0] L[1] etc etc and then use {data.sum:L} or use PHP
return $this->data("L01") + $this->data("L02") etc etc
Then in save data action use {var:phpblockname}
This topic is locked and no more replies can be posted.