如何创建前端有提交表单的小部件?原因是我正在自学插件开发,在将小部件添加到侧栏后,我正在努力学习如何在前端显示表单。
迄今为止我的代码
function widget ($args,$instance) {
extract( $args );
/* Our variables from the widget settings. */
$title = apply_filters(\'widget_title\', $instance[\'title\'] );
$name = $instance[\'name\'];
$number = $instance[\'number\'];
$message = $instance[\'message\'];
/* Before widget (defined by themes). */
echo $before_widget;
/* Display the widget title if one was input (before and after defined by themes). */
if ( $title )
echo $before_title . $title . $after_title;
?>
<p>
<label for="<?php echo $this->get_field_id( \'title\' ); ?>"><?php _e(\'Title:\', \'hybrid\'); ?></label>
<input id="<?php echo $this->get_field_id( \'title\' ); ?>" name="<?php echo $this->get_field_name( \'title\' ); ?>" value="<?php echo $instance[\'title\']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( \'name\' ); ?>"><?php _e(\'Your Name:\', \'name\'); ?></label>
<input id="<?php echo $this->get_field_id( \'name\' ); ?>" name="<?php echo $this->get_field_name( \'name\' ); ?>" value="<?php echo $instance[\'name\']; ?>" />
</p>
<!-- Your Name: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( \'number\' ); ?>"><?php _e(\'Your Cellphone Number:\', \'number\'); ?></label>
<input id="<?php echo $this->get_field_id( \'number\' ); ?>" name="<?php echo $this->get_field_name( \'number\' ); ?>" value="<?php echo $instance[\'number\']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( \'message\' ); ?>"><?php _e(\'Your Message:\', \'message\'); ?></label>
<textarea id="<?php echo $this->get_field_id( \'message\' ); ?>" name="<?php echo $this->get_field_name( \'message\' ); ?>"><?php echo $instance[\'message\']; ?></textarea>
</p>
<?php
/* After widget (defined by themes). */
echo $after_widget;
}