Jump to content

Select Options (radio)


entschleunigung
 Share

Recommended Posts

Hello, everyone,

i have created a radio field as follows

1=Mr|Mr
2=Ms|Ms

the following is output in the source code:

<input type="radio" name="name" id="id" class="class" value="1">

but I need:

<input type="radio" name="name" id="id" class="class" value="mr">

how do I get the value to be output instead of the id?

thx 

Link to comment
Share on other sites

@entschleunigung Why do you want to change the format though? SelectOptions are saved by ID, so that you can change the values and labels of individual options without changing selected options in existing pages. If you change the output format, you'll have to change the format they are saved in as well, that will require hooks also. Why not just let the module save the options as IDs and output the values / titles in your templates as you need them? Users don't see the value of the options in a radio input, after all ... just the labels. Or are the labels not rendering for you?

Link to comment
Share on other sites

hi @MoritzLost,

you are right of course, normally i don't have to change the format, but in this case i send the information to an external source (subscribe newsletter) that can only handle values like "mr" or "ms". 
(to complete it: via the LoginRegister module a user is registered and at the same time the newsletter registration is done) 

sorry if the information comes in bits and pieces, but i thought if i write the following, as described in the document 

1=mr|Mr

that in this case ProcessWire will take the value instead of the ID when the input radio is rendered.

it seems i was on the wrong track ?

greetings & servus

 

Link to comment
Share on other sites

Well, if you look through the database, you can see that SelectOption fields are always saved by ID (i.e. the value that goes into the database for this field is the selected option's ID). The mapping of IDs to values and labels is done through the central field definition. So changing that would be a lot of work. Can't you change the API call (or whatever) to the external service to use the value instead of the ID?

  • Like 1
Link to comment
Share on other sites

thanks first. as soon as i get back to the office, i'm gonna go test this out. as louis suggested, maybe it could work out that way:

"salutation" => $user->my_field->title;

 

currently, it's like this

"salutation" => $user->my_field;

and only the ID goes out there.

 

vor lauter bäumen und so ... thx 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...