Reputation: 1
I am a beginner in this PHP programming so want anyone to change my code to submit code when press submit page refresh I don't want refresh.
Please someone put ajax submit in this codes.
<div class="tab-pane" id="email">
<?php
require_once ('includes/emailchange.php');
?>
<? echo $Saved2;?>
<form action="" method="POST" class="form-horizontal">
<div class="form-group">
<label for="inputExperience" class="col-sm-3 control-label">Security Code:</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="SecurityCode" id="inputName" placeholder="Security Code">
</div>
</div>
<? echo $SecurityCode_error;?>
<div class="form-group">
<label for="inputName" class="col-sm-3 control-label">Security Question</label>
<div class="col-sm-9">
<select name="SecurityQuestion" class="form-control">
<option selected="selected" value="empty">Please Select</option>
<option value="What city were you born in?">What city were you born in?</option>
<option value="Who is your favorite person?">Who is your favorite person?</option>
<option value="What was your nickname?">What was your nickname?</option>
<option value="What's your favorite food?">What's your favorite food?</option>
<option value="What is your pet's name?">What is your pet's name?</option>
<option value="Who is your super hero?">Who is your super hero?</option>
<option value="What is your favorite sport?">What is your favorite sport?</option>
<option value="Who was your first teacher?">Who was your first teacher?</option>
<option value="What is your hobby?">What is your hobby?</option>
<option value="What was your first job?">What was your first job?</option>
</select>
</div>
</div>
<? echo $SecurityQuestion_error; ?>
<div class="form-group">
<label for="inputExperience" class="col-sm-3 control-label">Security Answer:</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="SecurityAnswer" id="inputName" placeholder="Security Answer">
</div>
</div>
<? echo $SecurityAnswer_error;?>
<div class="form-group">
<label for="inputName" class="col-sm-3 control-label">New E-mail Address:</label>
<div class="col-sm-9">
<input type="email" class="form-control" name="NewEmail1" id="inputName" placeholder="[email protected]">
</div>
</div>
<? echo $NewEmail1_error;?>
<div class="form-group">
<label for="inputName" class="col-sm-3 control-label">Verify E-mail Address:</label>
<div class="col-sm-9">
<input type="email" class="form-control" name="NewEmail2" id="inputName" placeholder="[email protected]">
</div>
</div>
<? echo $NewEmail2_error;?>
<div class="form-group">
<label for="inputName" class="col-sm-3 control-label">Captcha:</label>
<div class="col-sm-9">
<style>
.label-new {
position: relative;
top: 0;
padding: 10px 15px;
font-size: 17px;
color: #fbfbfb;
background-color: #212528 !important;
display: inline-block;
border-radius: 3px;
width: auto;
z-index: 2;
line-height: .5;
}
</style>
<h5 class="red-text label-new"><?php echo $new_string; ?></h5>
<input type="hidden" name="Captcha" value="<?php echo $new_string; ?>">
<input type="text" class="form-control" name="Captcha" placeholder="Captcha">
</div>
</div>
<? echo $Captcha_error; ?>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<input type="submit" name="changeemail" class="btn btn-danger" Value="Submit">
</div>
</div>
</form>
</div><!-- /.tab-pane -->
and this is emailchange.php
<?php
if (isset($_POST['changeemail'])) {
$SecurityCode=$_POST["SecurityCode"];
$SecurityQuestion=$_POST["SecurityQuestion"];
$SecurityAnswer=$_POST["SecurityAnswer"];
$NewEmail1=$_POST["NewEmail1"];
$NewEmail2=$_POST["NewEmail2"];
$Captcha = $_POST['Captcha'];
function check_email_address($NewEmail1)
{
// First, we check that there's one @ symbol,
// and that the lengths are right.
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $NewEmail1))
{
// NewEmail1 invalid because wrong number of characters
// in one section or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $NewEmail1);
$local_array = explode(".", $email_array[0]);
for
($i = 0; $i < sizeof($local_array); $i++)
{
if
(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
?'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
$local_array[$i]))
{
return false;
}
}
}
if(check_email_address($NewEmail1) )
{
$NewEmail1_error = '<font color="#FF0000">The New E-mail Address field is not a valid e-mail address.</font>';
$error .= '1';
}
if(check_email_address($NewEmail2) )
{
$NewEmail2_error = '<font color="#FF0000">The Verify E-mail Address field is not a valid e-mail address.</font>';
$error .= '1';
}
if ($NewEmail1 != $NewEmail2)
{
$NewEmail1_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
The New E-mail Address is Not Matched With The Verify E-mail Address.
</div>';
$error .= '1';
$NewEmail2_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
The Verify E-mail Address is Not Matched With The New E-mail Address.
</div>';
$error .= '1';
}
if(empty($NewEmail1) )
{
$NewEmail1_error = '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
New E-mail Address is Empty.
</div>';
$error .= '1';
}
if(empty($NewEmail2) )
{
$NewEmail2_error = '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Verify E-mail Address is Empty.
</div>';
$error .= '1';
}
if ($SecurityCode != $data['SecurityCode'])
{
$SecurityCode_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Security Code is Wrong.
</div>';
$error .= '1';
}
if(empty($SecurityCode))
{
$SecurityCode_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Security Code is Empty.
</div>';
$error .= '1';
}
if ($SecurityQuestion != $data['SecurityQuestion'])
{
$SecurityQuestion_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Security Question is Wrong.
</div>';
$error .= '1';
}
if(empty($SecurityQuestion))
{
$SecurityQuestion_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Security Question is Empty.
</div>';
$error .= '1';
}
if ($SecurityAnswer != $data['SecurityAnswer'])
{
$SecurityAnswer_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Security Answer is Wrong.
</div>';
$error .= '1';
}
if(empty($SecurityAnswer))
{
$SecurityAnswer_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Security Answer is Empty.
</div>';
$error .= '1';
}
if ($Captcha != $_POST['Captcha'])
{
$Captcha_error= '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Captcha SecurityCode is wrong..
</div>';
$error .= '1';
}
if (empty($Captcha) )
{
$Captcha_error ='<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Security SecurityCode is Empty.
</div>';
$error .= '1';
}
if (empty($error))
{
mysqli_select_db($conn1,$dbname1);
$change=mysqli_query($conn1,"UPDATE accounts SET Email='".$NewEmail1."' WHERE Username='".$acc."' ")or die(mysqli_error());
mysqli_select_db($conn2,$dbname2);
$change=mysqli_query($conn2,"UPDATE accounts SET Email='".$NewEmail1."' WHERE Username='".$acc."' ")or die(mysqli_error());
}
}
if (isset($change))
{
$Saved2 = '<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4> <i class="icon fa fa-check"></i> Alert!</h4>
Your E-mail Address is Ready To Use.
</div>';
}
?>
Please someone help me? Please help make ajax submit in this codes. I tried more time then didn't find any solution.
Upvotes: 0
Views: 67
Reputation: 1691
give your form an ID like id="form"
put your includes/emailchange.php as your form action (do not require it). You will need to address it properly in your form action and in the javascript below.
At the bottom of your page you need to put this between script tags
$(function () {
"use strict";
$("#form").submit(function () {
var data = $('#form').serialize();
$.ajax({
url: "includes/emailchange.php",
data: data,
type: "POST",
success: function (msg) {
$('#display').html(msg).delay(6000).fadeOut(1000);
}
});
return false;
});
});
This is to get you started. Work on it and change it as you see necessary
Upvotes: 1