Forums

radiobox values

ernst@volny.cz 15 Nov, 2020
how do I get to the radiobox values after submitting the form
I need to get to the color names.

1=red
2=blue
3= green

I know this description is stored next to the field in $this in ["options"], but I don't know the path to it. Or there is another way to find this value?
GreyHead 16 Nov, 2020
Hi ernst,

The simplest way is to use the names as values e.g. red=red

Bob
ernst@volny.cz 16 Nov, 2020
but i still need to work with rate "1" and "red"
i need both for further processing in the form
GreyHead 16 Nov, 2020
Hi Ernst,

You can use a few lines of custom code on submit to look up the 'extra' info you need.

Bob
ernst@volny.cz 16 Nov, 2020
I'm sorry, but I don't understand what you mean.

I write my own php codes and own javascripts in the form, but I don't know how to use them to get to the required information
healyhatman 17 Nov, 2020
In PHP

$values = [1 => 'red', 2 => 'blue'];

return $values[$this->data('radio_group_input_name')] ?? null;
ernst@volny.cz 17 Nov, 2020
I understand clearly, but I wanted to avoid entering values in two places
I did it by giving
1 <span>red</span>
and I control the display and calculations by working with strings

in this example it's not so understandable, but imagine I have an event and its price:
bar <span> 5 eur </span>
action 1 <span> 7 eur </span>
action 4 <span> 6 eur </span>
and I need to know the price and the action.
This is enough to write it once, but when writing
5=bar
7=action 1
6=action 4
I would have to change those values in the radiobox and in php
it would be user unfriendly
You need to login to be able to post a reply.