WordPress管理面板中的表单验证

时间:2019-11-15 作者:Foysal

我正在开发WordPress插件。在这方面,我通过Wordpress管理面板使用表单从用户收集数据。我的代码如下

<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> 
我的表单如下所示

enter image description here

如何在此处添加表单验证?

1 个回复
最合适的回答,由SO网友:Shah Alom 整理而成