Hey folks,
I am currently developing a series of RTF templates with php/MySQL..
The replacement of text and textareas is straightforward, but when I have an answer from radio button, then I want to populate either the 'yes' or 'no' box on the real form with an X..
Eg:
Do you like eggs:
X YES ___ NO
I have done this by putting a holder in for ech box in the RTF template like so:
Do you like eggs:
%eggs_y% YES %eggs_n% NO
and doing a simple:
if ($eggs == "yes"){
$output = str_replace( '%eggs_y%', 'X', $output );
$output = str_replace( '%eggs_n%', '__', $output );
} else if ($other_cases == "no"){
$output = str_replace( '%eggs_n%', 'X', $output );
$output = str_replace( '%eggs_y%', '__', $output );
}
There are literally hundreds of these in my project, so obviously I want to write a function where I can just pass the field name to it, and it spits the right '$output' back..like:
do_radio(eggs);
I am thinking something like...
function do_radio($field){
if ($field == "yes"){
$output = str_replace( '%$field_y%', 'X', $output );
$output = str_replace( '%$field_n%', '__', $output );
} else if ($field == "no"){
$output = str_replace( '%$field_n%', 'X', $output );
$output = str_replace( '%$field_y%', '__', $output );
}
}
but this is unsuccessful...
Im sure its just a syntactical problem, if anyone has any pointers or advice, Id be very glad to hear it 🙂.
Many thanks in advance.
Mik.e