Form validation in WordPress Admin Panel

admin2025-04-19  0

I am developing a WordPress plugin. In this regard I am gathering data from User using a Form via Wordpress Admin Panel. My code is like below

<form method="post" name="newAddress" id="newAddress" class="validate" novalidate="novalidate">
    <table class="form-table" role="presentation">
      <tr class="form-field form-required">
        <th scope="row">
          <label for="name">
            <?php _e( 'Name' ); ?>
          </label>
        </th>
        <td>
          <input name="name" type="text" id="name" value="<?php echo esc_attr( $new_user_login ); ?>" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60" />
        </td>
      </tr>
      <tr class="form-field form-required">
        <th scope="row">
          <label for="email">
            <?php _e( 'Email' ); ?>
          </label>
        </th>
        <td>
          <input name="email" type="email" id="email" value="<?php echo esc_attr( $new_user_email ); ?>" />
        </td>
      </tr>
      <tr class="form-field">
        <th scope="row">
          <label for="phone_no">
            <?php _e( 'Phone No' ); ?> 
          </label>
        </th>
        <td>
          <input name="phone_no" type="text" id="phone_no" value="<?php echo esc_attr( $new_user_firstname ); ?>" />
        </td>
      </tr>
      <tr class="form-field">
        <th scope="row">
          <label for="address">
            <?php _e( 'Address' ); ?> 
          </label>
        </th>
        <td>
          <input name="address" type="text" id="address" value="<?php echo esc_attr( $new_user_lastname ); ?>" />
        </td>
      </tr>
      <tr class="form-field">
        <th scope="row">
          <label for="photo">
            <?php _e( 'Photo' ); ?>
          </label>
        </th>
        <td>
          <input name="photo" type="text" id="photo" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" />
        </td>
      </tr>
    </table>
    <?php submit_button( __( 'Add New Address' ), 'primary', 'newAddress', true, array( 'id' => 'newAddress' ) ); ?>
  </form> 

My Form looks like below

How can I add Form validation here ?

I am developing a WordPress plugin. In this regard I am gathering data from User using a Form via Wordpress Admin Panel. My code is like below

<form method="post" name="newAddress" id="newAddress" class="validate" novalidate="novalidate">
    <table class="form-table" role="presentation">
      <tr class="form-field form-required">
        <th scope="row">
          <label for="name">
            <?php _e( 'Name' ); ?>
          </label>
        </th>
        <td>
          <input name="name" type="text" id="name" value="<?php echo esc_attr( $new_user_login ); ?>" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60" />
        </td>
      </tr>
      <tr class="form-field form-required">
        <th scope="row">
          <label for="email">
            <?php _e( 'Email' ); ?>
          </label>
        </th>
        <td>
          <input name="email" type="email" id="email" value="<?php echo esc_attr( $new_user_email ); ?>" />
        </td>
      </tr>
      <tr class="form-field">
        <th scope="row">
          <label for="phone_no">
            <?php _e( 'Phone No' ); ?> 
          </label>
        </th>
        <td>
          <input name="phone_no" type="text" id="phone_no" value="<?php echo esc_attr( $new_user_firstname ); ?>" />
        </td>
      </tr>
      <tr class="form-field">
        <th scope="row">
          <label for="address">
            <?php _e( 'Address' ); ?> 
          </label>
        </th>
        <td>
          <input name="address" type="text" id="address" value="<?php echo esc_attr( $new_user_lastname ); ?>" />
        </td>
      </tr>
      <tr class="form-field">
        <th scope="row">
          <label for="photo">
            <?php _e( 'Photo' ); ?>
          </label>
        </th>
        <td>
          <input name="photo" type="text" id="photo" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" />
        </td>
      </tr>
    </table>
    <?php submit_button( __( 'Add New Address' ), 'primary', 'newAddress', true, array( 'id' => 'newAddress' ) ); ?>
  </form> 

My Form looks like below

How can I add Form validation here ?

Share Improve this question edited Nov 15, 2019 at 12:52 abu abu 2031 silver badge9 bronze badges asked Nov 15, 2019 at 4:28 FoysalFoysal 4451 gold badge5 silver badges16 bronze badges 3
  • 1 Fyi, second parameter of the _e() and __() functions is textdomain. Without textdomain your plugin will work but your plugin needs to follow the standard if you like to submit the plugin in WordPress repository. – Shah Alom Commented Nov 15, 2019 at 16:06
  • Thank you @ShahAlom vai. Could you please explain more ? – Foysal Commented Nov 15, 2019 at 17:11
  • wordpress.stackexchange/questions/75759/… – Shah Alom Commented Nov 16, 2019 at 18:11
Add a comment  | 

1 Answer 1

Reset to default 2

Data Sanitization in Wordpress ... https://developer.wordpress/themes/theme-security/data-sanitization-escaping/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745001333a279244.html

最新回复(0)