小部件未保存的单选按钮
Posted
技术标签:
【中文标题】小部件未保存的单选按钮【英文标题】:Widget unsaved radio buttons 【发布时间】:2018-01-30 00:31:19 【问题描述】:如何保存我当前的“就业状态”(表单功能)并在前端显示(小部件功能)?
// Create the widget output.
public function widget( $args, $instance )
$title = apply_filters( 'widget_title', $instance[ 'title' ] );
$employment = apply_filters( 'widget_title', $instance[ 'employment' ] );
echo $args['before_widget'] . $args['before_title'] . $title . $args['after_title']; ?>
<p>Current state of employment: <?php echo $employment ?></p>
<?php echo $args['after_widget'];
// Create the admin area widget settings form.
public function form( $instance )
$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
$employment = ! empty( $instance['employment'] ) ? $instance['employment'] : 'help';
?>
<p>
<label> Current State of employment:</label><br>
<input for="<?php echo $this->get_field_id( 'employment' ); ?>" type="radio" name="employment" value="employed"> Employed<br>
<input for="<?php echo $this->get_field_id( 'employment' ); ?>" type="radio" name="employment" value="unemployed"> Unemployed<br>
</p>
<?php
【问题讨论】:
查看***.com/questions/45752478/… 【参考方案1】:试试这个代码
<input type="radio" <?php checked($instance[ 'employment' ] ,'employment'); ?> id="<?php echo $this->get_field_id( 'employment' ); ?>" value="employment" name="<?php echo $this->get_field_name( 'employment' ); ?>" ><br>
<input type="radio" <?php checked($instance[ 'employment' ] ,'unemployed'); ?> id="<?php echo $this->get_field_id( 'unemployed' ); ?>" value="unemployed" name="<?php echo $this->get_field_name( 'employment' ); ?>" >
【讨论】:
以上是关于小部件未保存的单选按钮的主要内容,如果未能解决你的问题,请参考以下文章