WordPress.org

Forums

[resolved] Have I used is_email() correctly for this email field? (2 posts)

  1. matthewpolld
    Member
    Posted 11 months ago #

    Hello,

    I'm building my first widget. I need to add an email field to my widget, is this correct please? Should I use is_email() ?

    function update($new_instance, $old_instance) {
         $instance = $old_instance;
         $instance['email'] = is_email($new_instance['email']);
    
        return $instance;
         }

    And

    function form($instance) {
    
         $email = sanitize_email($instance['email']);
              ?>
    
     <p>
        <label for="<?php echo  $this->get_field_id('email'); ?>">
         <?php _e('Email'); ?>  </label>
         <input class="widefat" id="<?php echo $this->get_field_id('email'); ?>" name="<?php echo $this->get_field_name('email'); ?>" type="email" value="<?php echo $email; ?> " />
        </p>
        <?php
        }

    Please can someone advise? I would really appreciate some help. Thanks

  2. matthewpolld
    Member
    Posted 11 months ago #

    is_email() is OK.

    esc_attrshould be used instead ofsanitize_email

Reply

You must log in to post.

About this Topic