Skip to content

Instantly share code, notes, and snippets.

@norcross
Created October 24, 2011 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norcross/1310022 to your computer and use it in GitHub Desktop.
Save norcross/1310022 to your computer and use it in GitHub Desktop.
Aweber Opt-in Widget
<?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');" ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment