OK, it’s a little complicated but here’s how I would do it.
First, define all your long text labels as strings or elements in an array.
Then set up your radio buttons (or whatever) to have option names that are unique, like a,b,c
Then, capture the fields that need the long strings and substitute the a, b or c that you set up in the field with the long string.
Simple idea, but in practice there’s details that complicate it. Here’s the code I came up with…
First, define your strings:
$string_a = 'Substitute string that is very very long.';
$string_b = 'Another very long string that I have to use.';
Put that at the top of the template, inside of the PHP tags.
Set up your radio button with the values of “a, b, c” These can be any unique string–they have to be unique so we know which string to replace it with and there won’t be any confusion. We want to replace ‘a’ with $string_a, etc. Our radio button has the name ‘city’
Then, set up your intercept:
<?php
if ( in_array( $this->field->name, array('city','state') ) ) {
ob_start();
$this->field->print_element();
$radiobuttons = ob_get_clean();
$output = str_replace( array("\na\n","\nb\n"), array($string_a,$string_b), $radiobuttons);
echo $output;
} else $this->field->print_element();
?>
“in_array” just looks for the field names of the fields that you want to substitute, so you just load that array up with all their names.
“ob_start()” captures the output of the radio buttons so we can change them instead of displaying them.
Once we’ve captured the output, we transfer the contents of the buffer into the variable $radiobuttons, and then we make our substitution. Now, because we don’t want to grab the “value” attribute of the input tag, we have to look for the line breaks around the label text, which is what we want to substitute. We do that by putting “\n” on both sides of the letter we are looking for. “str_replace” does the replacing: we have two arrays, one that is a list of all the short strings we want to match, and the second that is the long strings we want to replace them with. They have to both be in the same order.
So, there’s the idea, which I’m sure you can expand to give you want you want.
Have fun!