0

I have a form in a Wordpress site which comes from a plugin (Indeed Ultimate Membership Pro).

The form code looks something like this

<form method="post" id="ihc_login_form">
  <input type="hidden" name="ihcaction" value="login">
  <input type="hidden" name="ihc_login_nonce" value="f27d595767">
  <div class="impu-form-line-fr">
    <input type="text" value="" id="iump_login_username" name="log" placeholder="Username">
  </div>
  <div class="impu-form-line-fr">
    <input type="password" value="" id="iump_login_password" name="pwd" placeholder="Password">
  </div>
  <div class="impu-form-line-fr impu-form-submit">
    <input type="submit" value="Log In" name="Submit">
  </div>
</form>

What I want is to get the username and password from the form, assign the values in a variable and create a new user if the email domain is "@xyz.com", in functions.php file.

Example: If a user who is not registered in the site tries to login and his email is anything@xyz.com the values should be checked in functions.php and user should be created. Its like registering and logging in at the same time

EDIT This is my code in functions.php

function wpb_admin_account(){
$user = $_POST["log"];
$pass = '123456';
$email = $_POST["log"];
if ( !username_exists( $user )  && !email_exists( $email ) && strstr($email, "@xyz.com")) {
    $user_id = wp_create_user( $user, $pass, $email );
    $user = new WP_User( $user_id );
    $user->set_role( 'subscriber' );
    sleep(3);
    $url = "https://siteurl.com/my-account/";
    wp_redirect($url);
    exit;
} }
add_action('init','wpb_admin_account');

I've been successfull in getting the data and creating an account but it does not redirect to my-account page

  • 2
    This is more of a specification than a question. What have you tried? Where exactly are you stuck? Show us your attempt and explain what happens and what you expect to happen. – M. Eriksson Jul 12 '21 at 09:40
  • I'm stuck at getting the values from the form in functions.php file. Once i Get the values I can manage to register the user – Muhammad Assane Jul 12 '21 at 09:42
  • Like I said in my previous comment. Show us your attempt and explain what happens and what you expect to happen. Where here to help you sort out specific issues with your existing code, but for us to be able to do that, we need to see what you've done so far. – M. Eriksson Jul 12 '21 at 09:44
  • I've updated the question as you said, a help would be really appreciated – Muhammad Assane Jul 12 '21 at 09:50
  • `alert()` is a javascript function, not a PHP function. – M. Eriksson Jul 12 '21 at 09:51
  • What do I do to know if it's working or not @MagnusEriksson – Muhammad Assane Jul 12 '21 at 09:59
  • You can do `var_dump($_POST); exit;` That will dump the contents of the variable(s) you pass to it, and `exit;` will stop the script from continuing to execute (good while debugging specific values at specific points in your code) – M. Eriksson Jul 12 '21 at 10:03
  • Hey @MagnusEriksson. I've managed to come this far can you take a look and let me know why the user is not redirected. It just kinda refreshes the page, but the next time i log in it works perfectly. I've tried removing sleep but it still doesnt wok – Muhammad Assane Jul 12 '21 at 11:19

1 Answers1

1

As the form is from another plugin, first check if it has the extend option to modify submit queries if not, then you can add a custom jquery ajax to send the data to backend from frontend.

  • Hello, The plugin does not have any option to modify submit queries. Can you give an example of how can I send the data using ajax step by step as I'm not very familiar with ajax – Muhammad Assane Jul 12 '21 at 11:30
  • its a long process, but I am providing you a sample. hopefully It will work for your purpose. https://stackoverflow.com/questions/43557755/how-to-call-ajax-in-wordpress if you can not able to make it work, let me know. I will share live sample. – Mohammad Sohanur Rahman Jul 12 '21 at 11:46