With a WordPress PHP template - I what doing an if statement to check if user is logged in, if he is then I want to show an email form and if he's not I want to ask users to login.
<?php if ( is_user_logged_in() ) {
<div role="tabpanel" class="tab-panel active" id="nomessage">
<div class="row">
<div class="col-lg-12">
<h4>You have to be <a href="/login/" target="_blank">logged in</a> to send a message</h4>
</div>
</div>
</div>
} else {
<div class="tab-content">
<?php if($classieraToAuthor == 1){?>
<div role="tabpanel" class="tab-pane active" id="message">
<!--ShownMessage-->
<?php if(isset($_POST['submit']) && $_POST['submit'] == 'send_message'){?>
<div class="row">
<div class="col-lg-12">
<?php if($hasError == true){ ?>
<div class="alert alert-warning">
<?php echo $errorMessage; ?>
</div>
<?php } ?>
<?php if($emailSent == true){ ?>
<div class="alert alert-success">
<?php echo $classieraContactThankyou; ?>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<!--ShownMessage-->
<form method="post" class="form-horizontal" data-toggle="validator" name="contactForm" action="<?php the_permalink(); ?>">
<div class="form-group">
<label class="col-sm-3 control-label" for="name"><?php esc_html_e('Name', 'classiera') ?> :</label>
<div class="col-sm-9">
<input id="name" data-minlength="5" type="text" class="form-control form-control-xs" name="contactName" placeholder="<?php esc_html_e('Type your name', 'classiera') ?>" required>
</div>
</div><!--name-->
<div class="form-group">
<label class="col-sm-3 control-label" for="email"><?php esc_html_e('Email', 'classiera') ?> :</label>
<div class="col-sm-9">
<input id="email" type="email" class="form-control form-control-xs" name="email" placeholder="<?php esc_html_e('Type your email', 'classiera') ?>" required>
</div>
</div><!--Email-->
<div class="form-group">
<label class="col-sm-3 control-label" for="subject"><?php esc_html_e('Subject', 'classiera') ?> :</label>
<div class="col-sm-9">
<input id="subject" type="text" class="form-control form-control-xs" name="subject" placeholder="<?php esc_html_e('Type your subject', 'classiera') ?>" required>
</div>
</div><!--Subject-->
<div class="form-group">
<label class="col-sm-3 control-label" for="msg"><?php esc_html_e('Message', 'classiera') ?> :</label>
<div class="col-sm-9">
<textarea id="msg" name="comments" class="form-control" placeholder="<?php esc_html_e('Type Message', 'classiera') ?>" required></textarea>
</div>
</div><!--Message-->
<?php
$classieraFirstNumber = rand(1,9);
$classieraLastNumber = rand(1,9);
$classieraNumberAnswer = $classieraFirstNumber + $classieraLastNumber;
?>
<div class="form-group">
<div class="col-sm-9">
<p>
<?php esc_html_e("Please input the result of ", "classiera"); ?>
<?php echo $classieraFirstNumber; ?> + <?php echo $classieraLastNumber;?> =
</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="humanTest"><?php esc_html_e('Answer', 'classiera') ?> :</label>
<div class="col-sm-9">
<input id="humanTest" type="text" class="form-control form-control-xs" name="humanTest" placeholder="<?php esc_html_e('Your answer', 'classiera') ?>" required>
<input type="hidden" name="humanAnswer" id="humanAnswer" value="<?php echo $classieraNumberAnswer; ?>" />
<input type="hidden" name="classiera_post_title" id="classiera_post_title" value="<?php the_title(); ?>" />
<input type="hidden" name="classiera_post_url" id="classiera_post_url" value="<?php the_permalink(); ?>" />
</div>
</div><!--answer-->
<input type="hidden" name="submit" value="send_message" />
<button class="btn btn-primary btn-block btn-sm sharp btn-style-one" name="send_message" value="send_message" type="submit"><?php esc_html_e( 'Send Message', 'classiera' ); ?></button>
</form>
</div>
};
?>
First, I have added an if statement to check whether the user is logged in or not, if he is the first element is shown where is tells the user it has to be logged in to send a message. Then, if he is logged in a message form is shown instead. Cannot get it to work, would appreciate all help a lot! Thanks in advance!