Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress-如何使用html在PHP中回显单选按钮?_Php_Html_Wordpress_Radio Button - Fatal编程技术网

Wordpress-如何使用html在PHP中回显单选按钮?

Wordpress-如何使用html在PHP中回显单选按钮?,php,html,wordpress,radio-button,Php,Html,Wordpress,Radio Button,我有一个表单,其中包括单选按钮,结果存储在数据库中(是或否)。我正在尝试从存储的数据库值设置所选的单选按钮,但在遵循几个推荐的解决方案后,我无法确定它。$existing\u millitary\u状态的回声返回“No”。因为我使用的是Wordpress,所以我必须从函数返回html,这就是为什么我使用html.=命名法 我得到的结果是没有选中“否”单选按钮。注意,我还没有提交表单,这将通过Ajax调用完成 在确认应检查单选按钮后,如何将其设置为“已检查” 非常感谢您的帮助 相关PHP: $ex

我有一个表单,其中包括单选按钮,结果存储在数据库中(是或否)。我正在尝试从存储的数据库值设置所选的单选按钮,但在遵循几个推荐的解决方案后,我无法确定它。$existing\u millitary\u状态的回声返回“No”。因为我使用的是Wordpress,所以我必须从函数返回html,这就是为什么我使用html.=命名法

我得到的结果是没有选中“否”单选按钮。注意,我还没有提交表单,这将通过Ajax调用完成

在确认应检查单选按钮后,如何将其设置为“已检查”

非常感谢您的帮助

相关PHP:

$existing_military_status = ( get_user_meta( $user_id, 'user-military-status', true ) ) ? get_user_meta( $user_id, 'user-military-status', true ) : '';

$html .= "<input id='yes' type='radio' name='user-military-status' value='Yes' if ($existing_military_status === 'Yes') echo 'checked=\"checked\"'>\n";
$html .= "<label for='yes'><span class='radio'>Yes</span></label>\n";
$html .= "</div>\n";
$html .= "<div id='military-no-container' style='float: left;' class='radio-container'>\n";
$html .= "<input id='no' type='radio' name='user-military-status' value='No' if ($existing_military_status === 'No') echo 'checked=\"checked\"'>\n";
$html .= "<label for='no'><span class='radio'>No</span></label>\n";
$html .= "</div>\n";
$existing\u millitary\u status=(get\u user\u meta($user\u id,'user millitary status',true))?获取用户元($user\u id,“用户军事状态”,true):“”;
$html.=“\n”;
$html.=“是\n”;
$html.=“\n”;
$html.=“\n”;
$html.=“\n”;
$html.=“否\n”;
$html.=“\n”;

PHP解释器无法区分字符串和PHP代码。我建议在字符串之外创建变量和条件语句

$isYes = ($existing_military_status === 'Yes') ? 'checked' : '';
$isNo  = ($existing_military_status === 'No') ? 'checked' : '';

$html = "<input id='yes' type='radio' name='user-military-status' value='Yes' " . $isYes . ">\n";
$html .= "<input id='no' type='radio' name='user-military-status' value='No' " . $isNo . ">\n";
$isYes=($existing\u millitary\u status==='Yes')?'勾选“:”;
$isNo=($existing\u millitary\u status=='No')?'勾选“:”;
$html=“\n”;
$html.=“\n”;

我是否可以将PHP封装在标记中,以便解释器能够区分PHP代码?我确实试过了,但没能成功。只是好奇,因为它会简化我的代码。我有很多单选按钮的完整表格。是的,你可以附上它。请看这里的答案,我没有报告说这工作很好。非常感谢。