October 25, 201114 yr I'm struggling with making a form I am working with sticky. I have everything working just as I'd like and submitting to Filemaker, I just need to make the radio buttons sticky. I am missing something, in the syntax and it has me stumped. I anyone can point me in the right direction it would be greatly appreciated. This line works. $html .= '<td width="25%" align="center"><input type="radio" name="regcheckin" value="Poor" /> </td>'; This line does not work. $html .= '<td width="25%" align="center"><input type="radio" name="regcheckin" value="Poor"' if ($_POST['regcheckin'] == 'Poor') echo'checked="checked"'' /> </td>'; I'd like the second line to work if possible.
October 26, 201114 yr Here is how I'd do it: if ($_POST['regcheckin'] == 'Poor'){ $checkedval =' checked="checked" '};//note the spaces before and after the text! } else { $checkedval = '': } $html .= '<td width="25%" align="center"><input type="radio" name="regcheckin" value="Poor"'. $checkedval .' /> </td>';
October 30, 201114 yr Syntax looks fine. I'd suggest you debug what's actually getting posted... at the top of your form processing page (presumably this page), chuck in a print_r($_POST); and take a look at the output From the code you've pasted above, in the second example you have [value="Poor"'] - there's an extra quote there - might be breaking your post content.
October 31, 201114 yr The syntax in the original second example isn't really OK, as it has an invalid If statement in the middle of it... The first suggestion looks good, or you could do something like: $html .= '<td width="25%" align="center"><input type="radio" name="regcheckin" value="Poor"'; if ($_POST['regcheckin'] == 'Poor') { $html .='checked="checked"' } $html .=' /> </td>';
October 31, 201114 yr Author Thank for the help everyone. This is the code I got working. I need to do more reading on how spacing impacts the code. I was really hoping to get it all on one line but it took a few. $html .= '<td width="25%" align="center"><input type="radio" name="regcheckin" value="Poor"'; if($_POST['regcheckin'] == 'Poor'){ $html .= 'checked="checked"';} $html .= ' /> </td>';
Create an account or sign in to comment