Reputation: 455
I have created a function to create a login registration form custom but I do not why when i click on submit for it is showing me 404 not found error i do not know why this is happening
unction registration_form( $name, $fname, $email, $password, $familyname, $username, $password, $gender) {
echo '
<div class="login-form">
<form action="' . get_site_url() . '/sign-up" method="post">
<div class="form-group">
<input type="text" name="name" placeholder="Name" value="' . ( isset( $_POST['name'] ) ? $name : null ) . '">
</div>
<div class="form-group">
<input type="text" name="fname" placeholder="Father Name" value="' . ( isset( $_POST['fname']) ? $fname : null ) . '">
</div>
<div class="form-group">
<input type="text" name="familyname" placeholder="Family Name" value="' . ( isset( $_POST['familyname']) ? $familyname : null ) . '">
</div>
<div class="form-group">
<input type="text" name="email" placeholder="Email" value="' . ( isset( $_POST['email']) ? $email : null ) . '">
</div>
<div class="form-group">
<input type="text" name="username" placeholder="Username" value="' . ( isset( $_POST['username']) ? $username : null ) . '">
</div>
<div class="form-group">
<input type="password" name="password" placeholder="Password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '">
</div>
<div class="form-group">
<label for="nickname">Gender</label>
<div><input type="radio" name="gender" value="Male"> Male</div>
<div><input type="radio" name="gender" value="Female"> Female</div>
</div>
<input type="submit" name="submit" value="Register"/>
<div class="form-group"><br>
Already have account with us <a href="'.get_site_url().'/log-in" title="" class="reg" id="">Login Here</a>
</div>
</form>
</div>
';
}
function complete_registration() {
global $name, $fname, $password, $familyname, $username, $password, $gender;
if ( 1 > count( $reg_errors->get_error_messages() ) ) {
$userdata = array(
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password,
'user_name' => $name,
'family_name' => $familyname,
'father_name' => $fname,
'gender' => $gender
);
$user = wp_insert_user( $userdata );
echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
}
}
function custom_registration_function() {
if ( isset($_POST['submit'] ) ) {
// sanitize user form input
$username = sanitize_user( $_POST['username'] );
$password = esc_attr( $_POST['password'] );
$email = sanitize_email( $_POST['email'] );
$name = esc_url( $_POST['name'] );
$fname = sanitize_text_field( $_POST['fname'] );
$familyname = sanitize_text_field( $_POST['familyname'] );
$gender = sanitize_text_field( $_POST['gender'] );
// call @function complete_registration to create the user
// only when no WP_error is found
complete_registration(
$username,
$password,
$email,
$name,
$fname,
$familyname,
$gender
);
} else {
registration_form(
$username,
$password,
$email,
$name,
$fname,
$familyname,
$gender
);
}
}
// Register a new shortcode: [cr_custom_registration]
add_shortcode( 'cr_custom_registration', 'custom_registration_shortcode' );
// The callback function that will replace [book]
function custom_registration_shortcode() {
ob_start();
custom_registration_function();
return ob_get_clean();
}
Above is the code I have created but when I click on submit it shows me 404 not found as it shoudn't be The link given in the action is same so i do not know why this is happening
Upvotes: 0
Views: 38
Reputation: 3738
You get a 404 because your form action is "sign-up" and I assume that you didn't create such an url. You need to create a page template that displays your custom form and assign it to a page which has the "sign-up" slug. Or you can create a virtual page, where you should process your form.
Details on how to create a virtual page in wordpress here: https://wordpress.stackexchange.com/questions/9870/how-do-you-create-a-virtual-page-in-wordpress
Upvotes: 1