dimanche 17 janvier 2016

Custom Registration form Handle form visibility

I want to hide a form in wordpress once I sucesfully registrerd the user however I cannot appear to get it working i have tried the usual hideme value in the form hidden fields to process that the form has indead been submited but still the form shows with its thank you message. Anyone got any ideas as to how to hide this form when its submited.

<?php
/**
 * Plugin Name:  Front End Regsistration  DB
 * Plugin URI: http://ift.tt/1QfbQBA
 * Description: This plugin allows users to put simple registration form on page , post or template using shortcode 
 * Version: 1.0.0
 * Author: David Buckley
 * Author URI: http://ift.tt/1QfbQBA
 * License: GPLv2
 */

define('WP_DEBUG',true);
define('dtni_REGISTRATION_INCLUDE_URL', plugin_dir_url(__FILE__).'includes/');
ob_start();


//add front end css and js
function dtni_customregform(){
    wp_enqueue_style('dtni_cr_css_and_js', dtni_REGISTRATION_INCLUDE_URL."front-style.css"); 
    wp_register_script('dtni_cr_css_and_js', dtni_REGISTRATION_INCLUDE_URL."font-script.js" );
    wp_enqueue_script('dtni_cr_css_and_js');
}
add_action('wp_footer','dtni_customregform');

// function to registration Shortcode
function dtni_registration_shortcode( $atts ) {
    global $wpdb, $user_ID; 
    $firstname='';
    $lastname='';
    $username='';
    $email='';

    /* //if looged in rediret to home page
    if ( is_user_logged_in() ) { 
        wp_redirect( get_option('home') );// redirect to home page
        exit;
    } */

    if(sanitize_text_field( $_POST['com_submit']) != ''){

        $keresztnév=sanitize_text_field( $_REQUEST['com_firstname'] );
        $családnév=sanitize_text_field( $_REQUEST['com_lastname'] );

        $username = sanitize_text_field(  $_REQUEST['com_username'] );
        $email = sanitize_text_field(  $_REQUEST['com_email']  );
        $password = $wpdb->escape( sanitize_text_field( $_REQUEST['com_password']));
        $status = wp_create_user($username,$password,$email);
        $succress ='';
        $error_msg='';

        if (is_wp_error($status))  {
             $error_msg = __('Username or Email already registered. Please try another one.',''); 
        } 
        else{
            $user_id=$status;
            update_user_meta( $user_id,'first_name', $keresztnév);
            update_user_meta( $user_id,'last_name', $családnév);

            $succress= __('Your are register successfully for this site.',''); 

            $user_info=get_userdata( $user_id );


            wp_new_user_notification( $username, $user_pass);
}


    }

         ?>

    <div class="digtalthinkersni-registration-form">

        <?php if($error_msg!='') { ?><div class="error"><?php echo $error_msg; ?></div><?php }  ?>
        <?php if($succress!='') { ?><div class="success"><?php echo $succress; ?></div><?php }  ?>

        <form  name="form" id="registration"  method="post">
            <div class="ftxt">
             <label><?php _e("Keresztnév: *",'');?></label> 
             <input id="com_firstname" name="com_firstname" type="text" class="input" required value=<?php echo $keresztnév; ?> > 
            </div><div class="ftxt">
             <label><?php _e("Családnév: *",'');?></label> 
             <input id="com_fullname" name="com_lastname" type="text" class="input" required value=<?php echo $családnév; ?> > 
            </div>

            <div class="ftxt">
             <label><?php _e("Felhasználói név :*",'');?></label> 
             <input id="com_username" name="com_username" type="text" class="input" required value=<?php echo $username; ?> >
            </div>
            <div class="ftxt">
            <label><?php _e("E-mail: *",'');?> </label>
             <input id="com_email" name="com_email" type="email" class="input" required value=<?php echo $email; ?> >
            </div>
            <div class="ftxt">
            <label><?php _e("Jelszó :*",'');?></label>
             <input id="password1" name="com_password" type="password" required class="input"  />
            </div>
            <div class="ftxt">

             <input id="password2" name="c_password" type="password" class="input"  />
             <label><?php _e("Jelszó még egyszer: * ",'');?></label>
            </div>
            <div class="ftxt">          
            <label>

    <?php _e("Newsletter Signup : ",'');?>
    <input type="checkbox" name="mc4wp-subscribe" value="1" />
</label>
            </div>
            <input type="hidden" name="action" id="action" value="hideme" />

            <div class="fbtn"><input type="submit" name='com_submit' class="button"  value="<?php _e("Regisztráció",'');?>"/> </div>
        </form>
    </div>
<?php   
}


//add registration shortcoode
add_shortcode( 'digtialthinkers-registration-form', 'dtni_registration_shortcode' );

?>

Basically what I am wanting it to do is register the user then let them no they have been reg also what is the best way to email the notification a user gets on signup so it doesnt change from wordpress best practice



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire