Hi people I’m trying to validate a custom form inside a custom plugin in wordpress. The question is the following:

I have the following form:

<?php if ($errores): ?>
        <ul style="color: #f00;">
            <?php foreach ($errores as $error): ?>
                <li> <?php echo $error ?> </li>
            <?php endforeach; ?>
        </ul>
 <?php endif; ?>
<form class="wordpress-ajax-form" method="post" action="<?php echo get_admin_url(); ?>admin-post.php">
<input type="text" name="first_name>
<input type="email" name="email"> 
<input type="text" name="cedula">
<input type="hidden" name="action" value="custom_action">
<button>Send</button>

In my functions.php file i have:

add_action('admin_post_custom_action', 'custom_action'); 
add_action('admin_post_nopriv_custom_action', 'custom_action'); 
function custom_action(){
  $errores = array();
   //here i will put the code to validate form example the email  
}

Then what I want to be validated in some fields as does the registration form for wordpress users. If the email is repeated, return me to the form with the data already placed before including the errors.

Thanks for the help

Read more here: How to validate a form inside a custom plugin of wordpress?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: