Jump to content

Wordpress Form hide after submittion


David38ni

Recommended Posts

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' );
	
?>
Link to comment
Share on other sites

  • 1 month later...

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 by jdlev
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.