I'm a newbie creating a WordPress plugin stuck with setting "checked" based on a variable value. I'm working on a custom form. I am struggling with syntax I think...
This is the bit that fails:
<input type="radio" name="reporter_alliance" id="reporter_talk" value="[TALK]" ' . if($currenta === "[TALK]"): . ' checked = "checked" '. ;'>
Here's the full function so far and the rest of it seems to work:
<?php
function report_roe_form( $reporter_alliance, $reporter_username)
{
$current_u = wp_get_current_user();
$current_uid = get_current_user_id();
$currenta = get_user_meta($current_uid, 'alliance', true)[0];
if($currenta === "[TALK]") echo 'true'; #test of the function (this works)
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
<div>
<label >Reporter Alliance <strong>*</strong></label>
<label for="reporter_chat">[CHAT]</label>
<input type="radio" name="reporter_alliance" id="reporter_chat" value="[CHAT]">
<label for="reporter_talk">[TALK]</label>
<input type="radio" name="reporter_alliance" id="reporter_talk" value="[TALK]" ' . if($currenta === "[TALK]"): . ' checked = "checked" '. ;'>
</div>
<div>
<label for="reporter_username">Reporter Username <strong>*</strong></label>
<input type="text" name="reporter_username" value="' . $current_u->user_login . '">
</div>
<div>
<input type="submit" name="submit" value="Submit"/>
</div>
</form>
';
}
?>
I've seen lots online showing I should put <?php ?>
around if($currenta === "[TALK]"): . ' checked = "checked" '. ;
but I've tried various combinations that all fail.
I've tried several different combinations of putting things in single and double quotes but I just cant seem to get it. Please can someone point a newbie in the right direction?