jeudi 1 janvier 2015

A data field is not inesrting into database table from custom registration form


My registration form working fine. All data inserting into database table but "About/Bio" field not inserting into database table. Please help me out



<?php

function registration_form( $username, $password, $email, $website, $bio ) {
echo '
<style>

div {
margin-bottom:2px;
}

input{
margin-bottom:4px;
}

</style>
';

echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
<div>
<label for="username">Username <strong>*</strong></label>
<input type="text" name="username" value="' . ( isset( $_POST['username'] ) ? $username : null ) . '">
</div>

<div>
<label for="password">Password <strong>*</strong></label>
<input type="password" name="password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '">
</div>

<div>
<label for="email">Email <strong>*</strong></label>
<input type="text" name="email" value="' . ( isset( $_POST['email']) ? $email : null ) . '">
</div>
<div>
<label for="email">Email <strong>*</strong></label>
<input type="text" name="confirm_email" value="' . ( isset( $_POST['confirm_email']) ? $confirm_email : null ) . '">
</div>

<div>
<label for="website">Website</label>
<input type="text" name="website" value="' . ( isset( $_POST['website']) ? $website : null ) . '">
</div>


</div>

<div>
<label for="bio">About / Bio</label>
<textarea name="bio">' . ( isset( $_POST['description']) ? $bio : null ) . '</textarea>
</div>
<input type="submit" name="submit" value="Register"/>
</form>


';
}

function registration_validation( $username, $password, $confirm_email, $email, $website, $bio ) {
global $reg_errors;
$reg_errors = new WP_Error;

if ( empty( $username ) || empty( $password ) || empty( $email ) ) {
$reg_errors->add('field', 'Required form field is missing');
}

if ( 4 > strlen( $username ) ) {
$reg_errors->add( 'username_length', 'Username too short. At least 4 characters is required' );
}
if ( username_exists( $username ) ){
$reg_errors->add('user_name', 'Sorry, that username already exists!');
}
if ( ! validate_username( $username ) ) {
$reg_errors->add( 'username_invalid', 'Sorry, the username you entered is not valid' );
}
if ( 5 > strlen( $password ) ) {
$reg_errors->add( 'password', 'Password length must be greater than 5' );
}
if ( !is_email( $email ) ) {
$reg_errors->add( 'email_invalid', 'Email is not valid' );
}
if ( $_POST['email'] !== $_POST['confirm_email'] ) {
$reg_errors->add( 'email_not_matched', "<strong>ERROR</strong>: E-mail is not match" );
}
if ( ! empty( $website ) ) {
if ( ! filter_var( $website, FILTER_VALIDATE_URL ) ) {
$reg_errors->add( 'website', 'Website is not a valid URL' );
}
}
if ( is_wp_error( $reg_errors ) ) {

foreach ( $reg_errors->get_error_messages() as $error ) {

echo '<div>';
echo '<strong>ERROR</strong>:';
echo $error . '<br/>';
echo '</div>';

}

}
}

function complete_registration() {
global $reg_errors, $username, $password, $email, $website, $bio;
if ( 1 > count( $reg_errors->get_error_messages() ) ) {
$userdata = array(
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password,
'user_url' => $website,
'description' => $bio
);
$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'] ) ) {
registration_validation(
$_POST['username'],
$_POST['password'],
$_POST['email'],
$_POST['confirm_email'],
$_POST['website'],
$_POST['description']
);

// sanitize user form input
global $username, $password, $email, $website, $bio;
$username = sanitize_user( $_POST['username'] );
$password = esc_attr( $_POST['password'] );
$email = sanitize_email( $_POST['email'] );
$website = esc_url( $_POST['website'] );
$bio = esc_textarea( $_POST['description'] );

// call @function complete_registration to create the user
// only when no WP_error is found
complete_registration(
$username,
$password,
$email,
$website,
$bio
);
}

registration_form(
$username,
$password,
$email,
$website,
$bio
);
}

// 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();
}

?>




Aucun commentaire:

Enregistrer un commentaire