I have a contact form that checks if some field is empty when you click on ‘complete order’
It should refresh the page and display the error message.
But im using a page rename (some easy way to rename pages and have multiple pages on same php page)
So i put the contact form in order.php?action=order
This is the code:
<?php
if(isset($_GET['action']) && $_GET['action'] != '') {
$action = $_GET['action'];
} else {
}
?>
<?php
if(isset($action)) {
if($action == 'order') {
?>
<div class="container">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<fieldset>
<?php if(isset($hasError)) { //If errors are found ?>
<p class="alert-message error">Opps! Looks like you forgot to fill some specify field, please <b>go back</p> and fill the empty field.</p>
<?php } ?>
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<div class="alert-message success">
<p style="color: white;" ><strong>Your Order has been Successfully Sent!</strong></p>
<p style="color: white;" >Thank you for submitting your order, <strong><?php echo $pname;?></strong>! Please check your Private Messages folder at <strong><?php echo $forum;?></strong>, as we will get back to you soon. You will redirect back to homepage in less than 5 seconds.<meta HTTP-EQUIV="REFRESH" content="5; url=http://justxp.plutohost.net/jonydesigns/index.php"></p>
</div>
<?php } ?>
<div class="formwarp">
<div class="tos1">
<input type="checkbox" id="new_info_yes" class="box1"> I agree to the <a href="#" style="color: #4fc5cf;" >Terms of Service</a>.
</div><br />
<div id="new_info_form">
<div class="clearfix">
<label for="subject">
<span class="coloring">Forums Name:</span>
</label>
<div class="input">
<select name="forumn" id="forumn" class="span6 required" role="select" aria-required="true">
<option value="slct">Please select a forum</option>
<option value="hackforums">Hackforums</option>
<option value="sythe">Sythe</option>
<option value="rune-server">Rune-Server</option>
</select>
</div>
<br />
<div id="slct" class="colors">You haven't selected any forum.</div>
<div id="hackforums" class="colors" style="display:none"> <span id="brdr">HackForums:</span> Discount Percent: <font color="green">10%</font> </div>
<div id="sythe" class="colors" style="display:none"> <span id="brdr">Sythe:</span> Discount Percent: <font color="green">15%</font> </div>
<div id="rune-server" class="colors" style="display:none"> <span id="brdr">Rune-Server:</span> Discount Percent: <font color="green">15%</font> </div>
<script type="text/javascript">
$(function() {
$('#forumn').change(function(){
$('.colors').hide();
$('#' + $(this).val()).show();
});
});
</script> </div>
<br />
<div class="clearfix">
<label for="name">
<span class="coloring">Forums Username:</span>
</label>
<div class="input">
<input type="text" name="forumuser" id="forumuser" value="" class="span6 required" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="phone">
<span class="coloring">Personal Name:</span>
</label>
<div class="input">
<input type="text" name="pname" id="pname" value="" class="span6 required" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="email">
<span class="coloring">Email Address:</span>
</label>
<div class="input">
<input type="text" name="email" id="email" value="" class="span6 required email" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="email">
<span class="coloring">PayPal Email Address:</span>
</label>
<div class="input">
<input type="text" name="ppemail" id="ppemail" value="" class="span6 required email" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="subject">
<span class="coloring">Product Type</span>
</label>
<div class="input">
<select name="product" id="product" class="span6 required" role="select" aria-required="true">
<option>Please select a product\project</option>
<option>PSD to HTML</option>
<option>Web Design</option>
<option>Thread Design</option>
<option>Logo Design</option>
<option>Banner Design</option>
<option>Thread design + Signature</option>
<option>Other (Please type in additional information field)</option>
</select>
</div>
</div><br />
<div style="margin-left: -13%;" id="line"></div><br />
<div class="clearfix">
<span class="coloring">Information</span>
<div class="input">
<textarea rows="8" name="message" id="message" class="span10 required" role="textbox" aria-required="true"></textarea>
</div>
</div>
<div class="clearfix">
<span class="coloring">View Information</span>
<div class="input">
<textarea rows="8" name="messageview" id="messageview" class="span10 required" role="textbox" aria-required="true"></textarea>
</div>
</div>
<div class="clearfix">
<label for="phone">
<span class="coloring">Additional Information:</span>
</label>
<div class="input">
<input type="text" name="additional" id="additional" value="Additional information regarding the product" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" class="span6 required" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="phone">
<span class="coloring">PSD link:</span>
</label>
<div class="input">
<input type="text" name="psd" id="psd" value="PSD link here" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" class="span6 required" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="phone">
<span class="coloring">Your Budget:</span>
</label>
<div class="input">
<input type="text" name="money" id="money" value="$0.00 Enter your budget" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" class="span6 required" role="input" aria-required="true" />
</div>
</div>
<div class="actionss">
<input type="submit" value="Complete Order" name="submit" id="submitButton" title="Click here to submit your message!" />
</div>
</fieldset>
</form>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('input#upload_yes').change(function(){
if($(this).is(':checked')) {
$("#upload_form").show();
} else {
$("#upload_form").hide();
}
});
$('input#new_info_yes').change(function(){
if($(this).is(':checked')) {
$("#new_info_form").slideDown(500);
} else {
$("#new_info_form").delay(300).slideUp(500);;
}
});
//Trigger the change event so the divs are initially shown or hidden.
$('input[type=checkbox]').trigger('change');
});
</script>
<?php
}
elseif($action == 'contact') {
?>
<!-- action=contact info here -->
<?php
}
}
?>
This starts the page ?action=order
<?php
if(isset($action)) {
if($action == 'order') {
?>
It displays the form and everything is ok..
But when you fill everything and click complete order, it redirects to order.php and it doesn’t display any alerts, it should display this alert if the order was sent:
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<div class="alert-message success">
<p style="color: white;" ><strong>Your Order has been Successfully Sent!</strong></p>
<p style="color: white;" >Thank you for submitting your order, <strong><?php echo $pname;?></strong>! Please check your Private Messages folder at <strong><?php echo $forum;?></strong>, as we will get back to you soon. You will redirect back to homepage in less than 5 seconds.<meta HTTP-EQUIV="REFRESH" content="5; url=http://justxp.plutohost.net/jonydesigns/index.php"></p>
</div>
<?php } ?>
And should display this error if something was empty:
<?php if(isset($hasError)) { //If errors are found ?>
<p class="alert-message error">Opps! Looks like you forgot to fill some specify field, please <b>go back</p> and fill the empty field.</p>
<?php } ?>
but it doesn’t show the error at all, all it does it redirect you to order.php page but if successful it just sends the email but will not display any alert.
How could I fix it or what is causing it to happen?
http://justxp.plutohost.net/jonydesigns/order.php?action=order
Sorry for the huge code, I just didn’t know how to ask this question more cleaner.
A right I solved it,
I put moved the errors section out of the page, to the start of , now it checks if there was an error or not, if yes it will display the errors or alerts.
Sorry for posting such an easy question ^^