Search the Community
Showing results for tags 'populating'.
-
Hi people, I'm new to PHP, and I'm having some real difficulties with trying to re-populate a radio button selection on a form. Basically, I'm working on a WordPress plugin which uses custom fields to create a Bet custom post type. I need to have my form submit the user input, then re-populate it so that if the user wants to edit and update the Bet data, they don't have to fill in the whole form details again, they can just edit what they need to, and update (re-submit) the form. I've managed to get all of the form elements re-populating, apart from a radio button. I've been trawling round the internet for most of yesterday evening and this morning, trying different things, but nothing I've found works for me. I'd really appreciate some help if anyone knows how to do this. Here's my code so far (non working) <?php $win_status = 'checked = "unchecked"'; $ew_status = 'checked = "unchecked"'; if (isset($bet_details_bet_type)) { $selected_radio = $bet_details_bet_type; if ($selected_radio == 'WIN') { $win_satus = 'checked = "checked"'; } elseif ($selected_radio == 'EW') { $ew_status = 'checked = "checked"'; } } echo '<label for="bet_details_bet_type">Bet Type: </label>'; echo '<input type="radio" name="bet_details_bet_type" id="bet_details_bet_type" value="WIN" '. esc_attr( $win_status) .' /> Win '; echo '<input type="radio" name="bet_details_bet_type" id="bet_details_bet_type" value="EW" '. esc_attr( $ew_status) .' /> Each Way </br>'; $bet_details_bet_type is the VARIABLE that gets sent to / pulled from $_POST I have another function which is handling that, which has the following in it. $bet_details_bet_type = $_POST['bet_details_bet_type']; update_post_meta( $post_id, 'bet_details_bet_type', $bet_details_bet_type ); I know that the sending and retrieving is working okay, as the Value is stored and retrieved when I update (submit) the bet, but I just can't seem to get the radio button to be re-checked to the value that was submitted. Again, if any can help with this I would be very grateful. Thanks, Dweezer
- 4 replies
-
- radio button
- re-populating
-
(and 2 more)
Tagged with: