David38ni Posted January 11, 2016 Share Posted January 11, 2016 I have this wordpress plugin im working on but what i want it to do is to hide the form on submit but its not working its still showing the form can anbody help. I am wanting to hide the form after submition define('WP_DEBUG',true); define('dtni_REGISTRATION_INCLUDE_URL', plugin_dir_url(__FILE__).'includes/'); ob_start(); //add front end css and js function dtni_slider_trigger(){ wp_enqueue_style('dtni_css_and_js', dtni_REGISTRATION_INCLUDE_URL."front-style.css"); wp_register_script('dtni_css_and_js', dtni_REGISTRATION_INCLUDE_URL."font-script.js" ); wp_enqueue_script('dtni_css_and_js'); } add_action('wp_footer','dtni_slider_trigger'); // 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', $fullname); 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_mail($user_info->user_email, 'User first and last name', sprintf('Hi we have added your first name :-% and last name:- % to our site.',$_POST['fullname'])); } } ?> <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' ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/300276-wordpress-form-hide-after-submittion/ Share on other sites More sharing options...
element121 Posted February 13, 2016 Share Posted February 13, 2016 What code did you try to use to hide the form? I can't see it looking quickly. If you are using JQuery you should be able to easily hide the form with .hide(), referencing the form by it's id attribute: $("#registration").hide(); Quote Link to comment https://forums.phpfreaks.com/topic/300276-wordpress-form-hide-after-submittion/#findComment-1531072 Share on other sites More sharing options...
jdlev Posted February 15, 2016 Share Posted February 15, 2016 (edited) Since your submitting the form to itself, why not just use an if-then statement based on available post variables? Shouldn't be too hard to implement: Something simple like this should do the trick: if (!isset($_POST['com_firstname']){ //show form } else { //hide form } Also, I'm not sure you actually need to sanitize the data. I remember reading that certain methods used by wpdb like $wpdb->insert, etc are sanitized automatically by the $wpdb class (someone who's a bit more familiar with the wpdb class in wordpress, feel free to correct me if I'm wrong, but I think that's the case) Edited February 15, 2016 by jdlev Quote Link to comment https://forums.phpfreaks.com/topic/300276-wordpress-form-hide-after-submittion/#findComment-1531146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.