There is a website on wordpress and a registration form in which (a required field) I want to get the user login by last name without displaying this field on the screen. To do this, I place the value displayed in the value of the last name in the field, but this option only works when you press the submit button again (for the first time, an error pops up, which swears at the unfilled required login field). How to fix this moment?

 <form name="registerform" class="registerform" id="registerform<?php $template->the_instance(); ?>" action="<?php $template->the_action_url( 'register' ); ?>" method="post"> <p><label for="last_name<?php $template->the_instance(); ?>">Фамилия:<span class="necessarily">*</span></label><input type="text" name="last_name" id="last_name<?php $template->the_instance(); ?>" class="regular-text" value="<?php $template->the_posted_value( 'last_name' ); ?>" /></p> <p class="submit"> <input type="hidden" name="user_login" id="user_login<?php $template->the_instance(); ?>" value="<?php $template->the_posted_value( 'last_name' ); ?>" class="regular-text" /> <input type="submit" name="wp-submit" id="wp-submit<?php $template->the_instance(); ?>" value="<?php esc_attr_e( 'Register', 'theme-my-login' ); ?>" /> <input type="hidden" name="redirect_to" value="<?php $template->the_redirect_url( 'register' ); ?>" /> <input type="hidden" name="instance" value="<?php $template->the_instance(); ?>" /> <input type="hidden" name="action" value="register" /> </p> </form> 
  • @ Vasya for what minus something? - Vasya
  • Presumably, someone does not like wp)) - borodatych
  • @borodatych is not a reason to fail everything. - Vasya
  • I’ve knocked off))) But it wasn’t me, I’m giving a tooth) - borodatych

1 answer 1

Try to look at the html-source form. The first time post-values ​​are not specified. What did you want to get, if you pound an empty value on the server?

A possible solution to the forehead is in the scripting area:

 <p><label for="IDLastName">Фамилия:</label> <input type="text" name="last_name" id="IDLastName" value="" /> </p> <input type="text" name="user_login" id="IDUserLogin" value="" /> <script> jQuery(function($) { $('#IDLastName').keyup(function() { $('#IDUserLogin').val($('#IDLastName').val()); }) }); </script>