public
Last active

Aweber Opt-in Widget

  • Download Gist
aweber_widget.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
<?php
/**
* Aweber widget
*/
class aweber_Widget extends WP_Widget {
function aweber_Widget() {
$widget_ops = array( 'classname' => 'aweber', 'description' => 'Displays the aweber opt-in form' );
$this->WP_Widget( 'aweber', 'Aweber Form', $widget_ops );
}
 
function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
echo $before_widget;
$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
echo '<p>'.$instance['form_text'].'</p>';
echo '<form class="aweber_form" method="post" action="http://www.aweber.com/scripts/addlead.pl">';
echo '<input type="hidden" name="listname" value="'.$instance['list_id'].'" />';
if (!empty($instance['thanks'])) {
echo '<input type="hidden" name="redirect" value="'.$instance['thanks'].'" />';
}
echo '<input type="hidden" name="meta_adtracking" value="sidebar_form" />';
echo '<input type="hidden" name="meta_message" value="1" />';
echo '<input type="hidden" name="meta_required" value="email" />';
echo '<input type="hidden" name="meta_forward_vars" value="0" />';
echo "<input type=\"text\" class=\"name\" name=\"name\" value=\"Your Name\" onfocus=\"if (this.value == 'Your Name') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Your Name';}\" />";
echo "<input type=\"text\" class=\"email\" name=\"email\" value=\"Your Email\" onfocus=\"if (this.value == 'Your Email') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Your Email';}\" />";
echo '<input type="submit" class="submit" name="submit" value="'.$instance['submit'].'" />';
echo '</form>';
echo $after_widget;
?>
<?php }
 
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['list_id'] = strip_tags($new_instance['list_id']);
$instance['thanks'] = strip_tags($new_instance['thanks']);
$instance['submit'] = strip_tags($new_instance['submit']);
$instance['form_text'] = $new_instance['form_text'];
return $instance;
}
 
/** @see WP_Widget::form */
function form($instance) {
$instance = wp_parse_args( (array) $instance, array(
'title' => '',
'form_text' => '',
'thanks' => '',
'submit' => 'Submit',
'list_id' => 'rosshudgenslist',
) );
$title = strip_tags($instance['title']);
$list_id = strip_tags($instance['list_id']);
$thanks = strip_tags($instance['thanks']);
$submit = strip_tags($instance['submit']);
$form_text = $instance['form_text'];
?>
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo isset( $instance['title'] ) ? $instance['title'] : ''; ?>" />
</label></p>
 
<p><label for="<?php echo $this->get_field_id( 'list_id' ); ?>"><?php _e( 'List ID:' ); ?>
<input class="widefat" id="<?php echo $this->get_field_id( 'list_id' ); ?>" name="<?php echo $this->get_field_name( 'list_id' ); ?>" type="text" value="<?php echo isset( $instance['list_id'] ) ? $instance['list_id'] : ''; ?>" />
</label></p>
 
<p><label for="<?php echo $this->get_field_id( 'thanks' ); ?>"><?php _e( 'Thank You Page URL' ); ?>
<input class="widefat" id="<?php echo $this->get_field_id( 'thanks' ); ?>" name="<?php echo $this->get_field_name( 'thanks' ); ?>" type="text" value="<?php echo isset( $instance['thanks'] ) ? $instance['thanks'] : ''; ?>" />
</label></p>
 
<p><label for="<?php echo $this->get_field_id( 'submit' ); ?>"><?php _e( 'Button Text' ); ?>
<input class="widefat" id="<?php echo $this->get_field_id( 'submit' ); ?>" name="<?php echo $this->get_field_name( 'submit' ); ?>" type="text" value="<?php echo isset( $instance['submit'] ) ? $instance['submit'] : ''; ?>" />
</label></p>
 
<label for="<?php echo $this->get_field_id('form_text'); ?>">Opt-In Content:</label>
<textarea class="widefat" cols="30" rows="4" id="<?php echo $this->get_field_id('form_text'); ?>" name="<?php echo $this->get_field_name('form_text'); ?>"><?php echo $form_text; ?></textarea>
<?php }
 
} // class
 
// register widget
 
add_action( 'widgets_init', create_function( '', "register_widget('aweber_Widget');" ) );
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.