if (trim($differentshipping) == '') {
    $differentshipping = 'no';
}
if (isset($_POST['updateproceed'])) {
    $fname = $_POST['fname'];
    if (trim($fname) == '') {
        array_push($errors, 'Please enter your first name.');
    }
    $lname = $_POST['lname'];
    if (trim($lname) == '') {
        array_push($errors, 'Please enter your last name.');
    }
    if (!is_user_logged_in()) {
        $email = $_POST['email'];
        $checkwpemail = checkWPFieldexist('user_email', $email);
        $checkwpusername = checkWPFieldexist('user_login', $email);
        if (trim($email) == '') {
            array_push($errors, 'Please enter your e-mail address.');
        } else {
            if (count($checkwpemail) > 0 || count($checkwpusername) > 0) {
                array_push($errors, 'E-mail address exist please try another.');
            }
        }
    }
    $address = $_POST['address'];
    if (trim($address) == '') {
        array_push($errors, 'Please enter your address.');
    }
    $address2 = $_POST['address2'];
    $city = $_POST['city'];
    if (trim($city) == '') {
function registerationform($attr = '')
{
    $plugins_url = plugins_url();
    $gender = 'Male';
    $data = '';
    global $wpdb, $countries;
    $prefix = $wpdb->base_prefix;
    $errors = array();
    if (isset($_POST['registered'])) {
        $fname = $_POST['fname'];
        if (trim($fname) == '') {
            array_push($errors, 'Please enter your first name.');
        }
        $lname = $_POST['lname'];
        if (trim($lname) == '') {
            array_push($errors, 'Please enter your last name.');
        }
        $email = $_POST['email'];
        $checkwpemail = checkWPFieldexist('user_email', $email);
        $checkwpusername = checkWPFieldexist('user_login', $email);
        if (trim($email) == '') {
            array_push($errors, 'Please enter your e-mail address.');
        } else {
            if (count($checkwpemail) > 0 || count($checkwpusername) > 0) {
                array_push($errors, 'E-mail address exist please try another.');
            }
        }
        $pwd = $_POST['pwd'];
        if (trim($pwd) == '') {
            array_push($errors, 'Please enter your password.');
        }
        $pwd2 = $_POST['pwd2'];
        if (trim($pwd2) == '') {
            array_push($errors, 'Please enter your confirm password.');
        }
        if (trim($pwd) != trim($pwd2)) {
            array_push($errors, 'Password is not same as confirm password.');
        }
        $address = $_POST['address'];
        if (trim($address) == '') {
            array_push($errors, 'Please enter your address.');
        }
        $address2 = $_POST['address2'];
        $city = $_POST['city'];
        if (trim($city) == '') {
            array_push($errors, 'Please enter your city name.');
        }
        $zipcode = $_POST['zipcode'];
        if (trim($zipcode) == '') {
            array_push($errors, 'Please enter your zipcode.');
        }
        $state = $_POST['state'];
        if (trim($state) == '') {
            array_push($errors, 'Please enter your state.');
        }
        $phone = $_POST['phone'];
        if (trim($phone) == '') {
            array_push($errors, 'Please enter your phone number.');
        }
        $country = $_POST['country'];
        $gender = $_POST['gender'];
        if (count($errors) <= 0) {
            $url = 'http://www.puyangan.com/register.php';
            $fields = array('usrname' => $email, 'email' => $email, 'fname' => $fname, 'pwd' => $pwd);
            //url-ify the data for the POST
            foreach ($fields as $key => $value) {
                $fields_string .= $key . '=' . $value . '&';
            }
            rtrim($fields_string, '&');
            //open connection
            $ch = curl_init();
            //set the url, number of POST vars, POST data
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, count($fields));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
            //execute post
            $result = curl_exec($ch);
            if (trim($result) != '1') {
                array_push($errors, $result);
            }
            curl_close($ch);
        }
        if (count($errors) <= 0) {
            $time = time();
            $pass = md5($pwd);
            $sql = "INSERT INTO `" . $prefix . "users` (`user_login`, `user_pass`,`user_email`,`user_nicename`, `user_registered`, `display_name`) VALUES ('{$email}', '{$pass}', '{$email}', '{$fname}', now(),'{$fname}')";
            $result = $wpdb->query($sql);
            if ($result == 1) {
                $wpuser_id = $wpdb->insert_id;
                wp_set_password($pwd, $wpuser_id);
                add_user_meta($wpuser_id, 'first_name', $fname);
                add_user_meta($wpuser_id, 'last_name', $lname);
                add_user_meta($wpuser_id, 'address', $address);
                add_user_meta($wpuser_id, 'address2', $address2);
                add_user_meta($wpuser_id, 'city', $city);
                add_user_meta($wpuser_id, 'zipcode', $zipcode);
                add_user_meta($wpuser_id, 'state', $state);
                add_user_meta($wpuser_id, 'phone', $phone);
                add_user_meta($wpuser_id, 'country', $country);
                add_user_meta($wpuser_id, 'gender', $gender);
                add_user_meta($wpuser_id, 'ship_fname', $fname);
                add_user_meta($wpuser_id, 'ship_lname', $lname);
                add_user_meta($wpuser_id, 'ship_address', $address);
                add_user_meta($wpuser_id, 'ship_address2', $address2);
                add_user_meta($wpuser_id, 'ship_city', $city);
                add_user_meta($wpuser_id, 'ship_zipcode', $zipcode);
                add_user_meta($wpuser_id, 'ship_state', $state);
                add_user_meta($wpuser_id, 'ship_phone', $phone);
                add_user_meta($wpuser_id, 'ship_country', $country);
                add_user_meta($wpuser_id, 'differentshipping', 'no');
                add_user_meta($wpuser_id, 'rich_editing', 'true');
                add_user_meta($wpuser_id, 'comment_shortcuts', 'false');
                add_user_meta($wpuser_id, 'admin_color', 'fresh');
                add_user_meta($wpuser_id, 'show_admin_bar_front', 'true');
                add_user_meta($wpuser_id, 'use_ssl', '0');
                add_user_meta($wpuser_id, 'aim', '');
                add_user_meta($wpuser_id, 'yim', '');
                add_user_meta($wpuser_id, 'jabber', '');
                add_user_meta($wpuser_id, 'show_welcome_panel', '2');
                $capkey = $prefix . 'capabilities';
                $capvalue = serialize(array('subscriber' => 1));
                $sql = "INSERT INTO `" . $prefix . "usermeta` (`user_id`, `meta_key`,`meta_value`) VALUES ('{$wpuser_id}', '{$capkey}', '{$capvalue}')";
                $result = $wpdb->query($sql);
                add_user_meta($wpuser_id, $prefix . 'user_level', 0);
                $to = $email;
                $subject = get_option('blogname') . ' : Registration Confirmation';
                $from = get_option('admin_email');
                $fromname = get_option('blogname');
                $headers = 'MIME-Version: 1.0' . "\r\n";
                $headers .= "Content-type: text/html; charset=utf-8" . "\r\nFrom: {$fromname} <{$from}>\r\nReply-To: {$from}";
                $message = "Dear " . $fname . " " . $lname;
                $message .= ",<br /><br />Thank you for registering with " . $fromname . ".<br />You can view or change your information by logging in to your account with the following login details:<br /><br />";
                $message .= 'Email: ' . $email;
                $message .= '<br />Password: '******'<br /><br />Thank You';
                @mail($to, $subject, $message, $headers);
                $to = get_option('admin_email');
                $subject = get_option('blogname') . ' : New user registered';
                $from = $email;
                $fromname = get_option('blogname');
                $headers = 'MIME-Version: 1.0' . "\r\n";
                $headers .= "Content-type: text/html; charset=utf-8" . "\r\nFrom: {$fromname} <{$from}>\r\nReply-To: {$from}";
                $message = "Dear Admin";
                $message .= ",<br /><br />New user is registered on " . $fromname . ".<br />Some detail is given below:<br /><br />";
                $message .= 'Email: ' . $email;
                $message .= '<br />First Name: ' . $fname;
                $message .= '<br />Last Name: ' . $lname;
                $message .= '<br /><br />Thank You';
                @mail($to, $subject, $message, $headers);
                @ob_start();
                wp_clear_auth_cookie();
                wp_set_auth_cookie($wpuser_id);
                $_SESSION['message'] = 'Thanks for registration.';
                echo "<script>window.location='" . get_option('home') . "'</script>";
                exit;
            }
        }
    }
    if (count($errors) > 0) {
        $data .= ' <table width="97%" border="0" cellpadding="3" cellspacing="3" align="center">';
        foreach ($errors as $error) {
            $data .= '<tr>
				<td align="left" valign="top" class="error">' . $error . '</td>
			  </tr>';
        }
        $data .= '</table>';
    }
    ?>
	   <script type="text/javascript">
	   jQuery(document).ready(function(){
	   		var p = jQuery('div.mid_content');
			var offset = p.offset();
			jQuery('html, body').animate({scrollTop : offset.top},1000);
			jQuery("#registrations").validate({
			  rules: {
				pwd: {
				  required: true,
				  minlength: 4
				},
				pwd2: {
				  required: true,
				  minlength: 4,
				  equalTo:'#pwd'
				}
			},
			  messages: {
					pwd: {
						required: "Please enter your password.",
						minlength: "Password must contain a minimum of 4 characters"
					},
					pwd2: {
						required: "Please enter your confirm password.",
						minlength: "Password must contain a minimum of 4 characters.",
						equalTo: "Confirm password does not match the password."
					}
				}
			});
	   });
	   </script>
	   <?php 
    $data .= '
				<form class="form-horizontal checkout" id="registrations" method="POST">
					<div class="newregisterform">
					
					<div class="field">
						<label for="fname">First Name*</label>
						<input type="text" name="fname" id="fname" class="required" value="' . $fname . '" />
					</div>
					<div class="field">
						<label for="lname">Last Name*</label>
						<input type="text" name="lname" id="lname" class="required" value="' . $lname . '" />
					</div>
					<div class="field">
						<label for="email">Email Address*</label>
						<input type="text" name="email" id="email" class="required email" value="' . $email . '" />
					</div>
					<div class="field">
						<label for="pwd">Password*</label>
						<input type="password" name="pwd" id="pwd" class="required" value="" />
					</div>
					<div class="field">
						<label for="pwd2">Confirm Password*</label>
						<input type="password" name="pwd2" id="pwd2" class="required" value="" />
					</div>
					<div class="field">
						<label for="address">Address*</label>
						<input type="text" name="address" id="address" class="required" value="' . $address . '" />
						<div class="clr"></div>
						<input type="text" name="address2" id="address2" value="' . $address2 . '" />
					</div>
					<div class="field">
						<label for="city">City*</label>
						<input type="text" name="city" id="city" class="required" value="' . $city . '" />
					</div>
					<div class="field">
						<label for="zipcode">Zip Code*</label>
						<input type="text" name="zipcode" id="zipcode" class="required" value="' . $zipcode . '" />
					</div>
					<div class="field">
						<label for="state">State*</label>
						<input type="text" name="state" id="state" class="required" value="' . $state . '" />
					</div>
					<div class="field">
						<label for="country">Country*</label>
						<select name="country" id="country">';
    if (count($countries) > 0) {
        foreach ($countries as $ctry) {
            $data .= '<option value="' . $ctry . '"';
            if ($country == $ctry) {
                $data .= ' selected="selected"';
            }
            $data .= '>' . $ctry . '</option>';
        }
    }
    $data .= '</select>
					</div>
					<div class="field">
						<label for="phone">Phone*</label>
						<input type="text" name="phone" id="phone" class="required" value="' . $phone . '" />
					</div>
					<div class="field">
						<label for="gender">Gender*</label>
						Male <input type="radio" name="gender" value="Male"';
    if ($gender == 'Male') {
        $data .= ' checked="checked"';
    }
    $data .= '/>
						Female <input type="radio" name="gender" value="Female"';
    if ($gender == 'Female') {
        $data .= ' checked="checked"';
    }
    $data .= '/>
					</div>
					<div class="checkoutbtn">
						<input type="submit" name="registered" value="Sign Up" />
					</div>
				</div>
				
				</form>
				';
    return $data;
}