PluginProbe
Smart Forms – when you need more than just a contact form / 0.8
Smart Forms – when you need more than just a contact form v0.8
trunk 0.5 0.5.5 0.6 0.7 0.8 0.8.5 0.9.1
smart-forms / widgets / smart-form-widget.php

smart-form-widget.php in Smart Forms – when you need more than just a contact form 0.8, at widgets/smart-form-widget.php

67 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_action( 'widgets_init', 'rednao_forms_register_widget' );
4
5 function rednao_forms_register_widget()
6 {
7 register_widget('rednao_smart_forms_widget');
8 }
9
10 class rednao_smart_forms_widget extends WP_Widget
11 {
12 function rednao_smart_forms_widget()
13 {
14 $widget_ops = array(
15 'classname' => 'rednao_smart_forms_widget', 'description' => 'Let you insert forms in any area'
16 );
17 $this->WP_Widget( 'rednao_smart_forms_widget', 'Smart Forms',$widget_ops );
18 }
19
20 function form($instance)
21 {
22 $defaults = array( 'form_id' => '0','title'=>'' );
23 $instance = wp_parse_args( (array) $instance, $defaults );
24 $id = $instance['form_id'];
25 $title=$instance['title'];
26
27 global $wpdb;
28 $results =$wpdb->get_results('select form_id,form_name from '.SMART_FORMS_TABLE_NAME);
29
30 ?>
31
32 <p class="description">
33 <?php echo __("Select a form."); ?>
34 </p>
35 <p><?php echo __("Title"); ?>
36 <input class="widefat" type="text" name="<?php echo $this->get_field_name("title");?>" value="<?php echo $title;?>"/>
37 </p>
38
39 <?php
40 echo "<select class='widefat' name='".$this->get_field_name("form_id")."'>";
41 foreach($results as $result)
42 {
43 echo "<option value='$result->form_id'".($id==$result->form_id?" selected='sel'":"" ).">";
44 echo $result->form_name;
45 echo "</option>";
46 }
47 echo "</select>";
48 }
49
50 function update($new_instance, $old_instance)
51 {
52 $new_instance['title'] =strip_tags($new_instance['title']);
53 $new_instance['form_id'] =strip_tags($new_instance['form_id']);
54
55 delete_transient("rednao_smart_forms_".$new_instance['form_id']);
56 return $new_instance;
57 }
58
59 function widget($args, $instance) { // displays the widget
60 $id=$instance['form_id'];
61 require_once(SMART_FORMS_DIR."smart-forms-helpers.php");
62 return rednao_smart_forms_load_form($instance['title'],$id,false);
63 }
64
65
66 }
67 ?>