How to create animation alert system with toastr and php mysql - javascript

Hi I want to create animation notification system with toastr and PHP MySQL, But I don't understand how can I do that. I already Integrate jQuery Toastr Plugin in my header and footer files I want to create like below picture
This is example Image
I'm new so I can't understand how I can do that. Please help me.
Below are my html and PHP code. Please tell me How I can call success message, warning message and error message.
<?php include_once('inc/header.php');
$database = new Database();
$db = $database->getConnection();
$addmouja = new Mutation($db);
?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<h4 class="page-title">নতুন মৌজা</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item">ড্যাশবোর্ড</li>
<li class="breadcrumb-item active">নতুন মৌজা</li>
</ol>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-12">
<div class="card font-18">
<div class="card-body">
<?php
if(isset($_POST['add_mouja'])){
$mouja_n = $_POST['mname'];
$mouja_jal = $_POST['mjal'];
if($addmouja->addMouja($mouja_n, $mouja_jal)){
echo '<script type="text/javascript">toastr.success("Have Fun")</script>';
}else{
echo "<div id='toastr-four'></div>";
}
}
?>
<form method="post">
<div class="row">
<div class="col-md-6">
<label for="moujaName" class="col-form-label">মৌজার নাম <span style="color: red">*</span></label>
<input type="text" class="form-control" name="mname" autocomplete="off" required>
</div>
<div class="col-md-6">
<label for="moujaJal" class="col-form-label">জে, এল নং <span style="color: red">*</span></label>
<input type="text" class="form-control" name="mjal" autocomplete="off" required>
</div>
</div>
<p class="text-center">
<button type="submit" name="add_mouja" class="btn btn-success mt-2">Add Mouja</button>
<button type="reset" class="btn btn-danger mt-2">Reset</button>
</p>
</form>
</div>
</div>
</div>
</div>
<?php include_once('inc/footer.php');?> ```

Related

How to dynamically change the price of paypal smartbutton according to the PHP cart value?

I am not able to assign the value of my shopping cart to the Paypal button in order for the user to be able to pay the correct amount.
The total price of the cart is stored as a variable $total_price:
<span class="metadata" id="totalprice" value="<?php echo $total_price ?>" > </span>
This is done to change it to something callable in Javascript.
Paypal's code from their developer website is as such:
<script>
var num = document.getElementById("totalprice").value;
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: num
}
}]
});
},
// Finalize the transaction
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
</script>
However by adding my variable as the value (as shown in the code above) every time I run the payment, the Paypal pop up briefly opens and then crashes.
I have also tried to create a Javascript variable containing the PHP variable and then setting value to that, but it had no effect.
Is there any way to solve this?
EDIT (this is my PHP code)
$cart_total=0;
if(isset($_POST['submit'])){
$address=obtain_values($connection,$_POST['address']);
$city=obtain_values($connection,$_POST['city']);
$pincode=obtain_values($connection,$_POST['pincode']);
$payment_type=obtain_values($connection,$_POST['payment_type']);
$user_id=$_SESSION['USER_ID'];
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($connection,'','',$key);
$price=$productArr[0]['price'];
$quantity=$val['qty'];
$cart_total=$cart_total+($price*$quantity);
}
$total_price=floatval($cart_total);
$payment_status='pending';
if($payment_type=='cod'){
$payment_status='success';
}
$order_status='2';
$added_on=date('Y-m-d h:i:s');
$txnid = substr(hash('', mt_rand() . microtime()), 0, 20);
mysqli_query($connection,"INSERT INTO order(user_id,address,city,pincode,payment_type,total_price,payment_status,order_status,added_on,txnid) VALUES('$user_id','$address','$city','$pincode','$payment_type','$total_price','$payment_status','$order_status','$added_on','$txnid')");
$order_id=mysqli_insert_id($connection);
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($connection,'','',$key);
$price=$productArr[0]['price'];
$quantity=$val['qty'];
mysqli_query($connection,"insert into `order_detail`(order_id,product_id,qty,price) values('$order_id','$key','$quantity','$price')");
echo "insert";
}
unset($_SESSION['cart']);
?>
<script>
window.location.href='thank_you.php';
</script>
<?php
}
?>
EDIT 2
<span class="metadata" id="totalprice" value="<?php echo ($total_price) ?>" > </span>
<div class="ht__bradcaump__area" style="background: rgba(0, 0, 0, 0) url(images/bg/ali1.png) no-repeat scroll center center / cover ;">
<div class="ht__bradcaump__wrap">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="bradcaump__inner">
<nav class="bradcaump-inner">
<a class="breadcrumb-item" href="index.html">Home</a>
<span class="brd-separetor"><i class="zmdi zmdi-chevron-right"></i></span>
<span class="breadcrumb-item active">checkout</span>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- End Bradcaump area -->
<!-- cart-main-area start -->
<div class="checkout-wrap ptb--100">
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="checkout__inner">
<div class="accordion-list">
<div class="accordion">
<?php
$accordion_class='accordion__title';
if(!isset($_SESSION['USER_LOGIN'])){
$accordion_class='accordion__hide';
?>
<div class="accordion__title">
Checkout Method
</div>
<div class="accordion__body">
<div class="accordion__body__form">
<div class="row">
<div class="col-md-6">
<div class="checkout-method__login">
<form id="login-form" method="post">
<h5 class="checkout-method__title">Login</h5>
<div class="single-input">
<input type="text" name="login_email" id="login_email" placeholder="Your Email*" style="width:100%">
<span class="field_error" id="login_email_error"></span>
</div>
<div class="single-input">
<input type="password" name="login_password" id="login_password" placeholder="Your Password*" style="width:100%">
<span class="field_error" id="login_password_error"></span>
</div>
<p class="require">* Required fields</p>
<div class="dark-btn">
<button type="button" class="fv-btn" onclick="user_login()">Login</button>
</div>
<div class="form-output login_msg">
<p class="form-messege field_error"></p>
</div>
</form>
</div>
</div>
<div class="col-md-6">
<div class="checkout-method__login">
<form action="#">
<h5 class="checkout-method__title">Register</h5>
<div class="single-input">
<input type="text" name="name" id="name" placeholder="Your Name*" style="width:100%">
<span class="field_error" id="name_error"></span>
</div>
<div class="single-input">
<input type="text" name="email" id="email" placeholder="Your Email*" style="width:100%">
<span class="field_error" id="email_error"></span>
</div>
<div class="single-input">
<input type="text" name="mobile" id="mobile" placeholder="Your Mobile*" style="width:100%">
<span class="field_error" id="mobile_error"></span>
</div>
<div class="single-input">
<input type="password" name="password" id="password" placeholder="Your Password*" style="width:100%">
<span class="field_error" id="password_error"></span>
</div>
<div class="dark-btn">
<button type="button" class="fv-btn" onclick="user_register()">Register</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="<?php echo $accordion_class?>">
Address Information
</div>
<form method="post">
<div class="accordion__body">
<div class="bilinfo">
<div class="row">
<div class="col-md-12">
<div class="single-input">
<input type="text" name="address" placeholder="Street Address" required>
</div>
</div>
<div class="col-md-6">
<div class="single-input">
<input type="text" name="city" placeholder="City/State" required>
</div>
</div>
<div class="col-md-6">
<div class="single-input">
<input type="text" name="pincode" placeholder="Post code/ zip" required>
</div>
</div>
</div>
</div>
</div>
<div class="<?php echo $accordion_class?>">
payment information
</div>
<div class="accordion__body">
<div class="paymentinfo">
<div class="single-method">
COD <input type="radio" name="payment_type" value="COD" required/>
PayPal <input type="radio" name="payment_type" value="paypal" onclick="showButton()" required/>
</div>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=ASCkJmx1-2CeTlk1ABMrnC4xJbalWvyLbv-mIx76k9644aZb49wX82Qrgcn6W15Y3Yvm6GrrfpehN_ib&currency=USD"></script>
<script>
document.getElementById("paypal-button-container").style.display = "none";
function showButton() {
var x = document.getElementById("paypal-button-container");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
<script>
var num = document.getElementById("totalprice").value;
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: num
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
</script>
<div class="single-method">
</div>
</div>
</div>
<input type="submit" name="submit"/>
</form>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="order-details">
<h5 class="order-details__title">Your Order</h5>
<div class="order-details__item">
<?php
$cart_total=0;
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($connection,'','',$key);
$pname=$productArr[0]['name'];
$mrp=$productArr[0]['mrp'];
$price=$productArr[0]['price'];
$image=$productArr[0]['image'];
$quantity=$val['qty'];
$cart_total=$cart_total+($price*$quantity);
?>
<div class="single-item">
<div class="single-item__thumb">
<img src="media/product/<?php echo $image?>" />
</div>
<div class="single-item__content">
<?php echo $pname?>
<span class="price"><?php echo $price*$quantity?></span>
</div>
<div class="single-item__remove">
<i class="icon-trash icons"></i>
</div>
</div>
<?php } ?>
</div>
<div class="ordre-details__total">
<h5>Order total</h5>
<span class="price"><?php echo $cart_total?></span>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require('footer.php')?>

php file not upload in ajax serialize

Here is my HTML
<form class="form form-vertical captcha_from" style="width: 50%;" method="post" action="<?php echo base_url('home/post_job_save'); ?>" enctype = "multipart/form-data">
<div class="container">
<div class="row form-group">
<div class="col-xs-12">
<ul class="nav nav-pills nav-justified thumbnail setup-panel">
<li class=""><a href="#step-1">
<h4 class="list-group-item-heading">Add Profile</h4>
<p class="list-group-item-text">First Step</p>
</a></li>
<li class=""><a href="#step-2">
<h4 class="list-group-item-heading">Add Resume</h4>
<p class="list-group-item-text">Second Step</p>
</a></li>
<li class=""><a href="#step-3">
<h4 class="list-group-item-heading">Add Cover Letter</h4>
<p class="list-group-item-text">Third Step</p>
</a></li>
<li class="active"><a href="#step-4">
<h4 class="list-group-item-heading">Add Photo</h4>
<p class="list-group-item-text">Fourth Step</p>
</a></li>
</ul>
</div>
</div>
<div class="row setup-content" id="step-1" >
<div class="col-xs-12">
<div class="col-md-12 well">
<h1>Add Profile</h1>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="control-group">
<label>First Name*</label>
<div class="controls">
<input type="text" class="form-control" placeholder="First Name" name="first_name" required="">
</div>
</div>
<div class="control-group">
<label>Last Name*</label>
<div class="controls">
<input type="text" class="form-control" placeholder="last Name" name="last_name" required="">
</div>
</div>
<div class="control-group">
<label>Email*</label>
<div class="controls">
<input type="email" class="form-control" placeholder="Email" name="email" required="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row setup-content" id="step-2">
<div class="col-xs-12">
<div class="col-md-12 well">
<h1 class="text-center">Add Resume</h1>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label for="file">Select a file to upload</label>
<input type="file" name="resume">
<p class="help-block">Only jpg,jpeg,png and gif file with maximum size of 1 MB is allowed.</p>
</div>
</div>
</div>
</div><!-- /container -->
</div>
</div>
</div>
<div class="row setup-content" id="step-3">
<div class="col-xs-12">
<div class="col-md-12 well">
<h1 class="text-center">Add Cover Letter</h1>
<div class="form-group">
<label for="file">Select a file to upload</label>
<input type="file" name="cover_letter">
<p class="help-block">Only jpg,jpeg,png and gif file with maximum size of 1 MB is allowed.</p>
</div>
</div>
</div>
</div>
<div class="row setup-content" id="step-4">
<div class="col-xs-12">
<div class="col-md-12 well">
<h1 class="text-center">Add Photo</h1>
<div class="form-group">
<label for="file">Select a file to upload</label>
<input type="file" name="photo">
<p class="help-block">Only jpg,jpeg,png and gif file with maximum size of 1 MB is allowed.</p>
</div>
<input type="submit" id="apply_job_save_submit" class="btn btn-primary btn-md" value="Submit">
</div>
</div>
</div>
</div></form>
Js Code
$('#apply_job_save_submit').on('click', function(e) {
$.ajax({
type: 'post',
url: base_url+'jobs/home/apply_job_save',
data: $('#apply_job_save').serialize(),
success: function () {
document.getElementById('createarea').innerHTML = "SUCCESS";
}
});
});
php code:
if(isset($_FILES) && $_FILES["resume"]["name"]!=''){
$org_filename=$_FILES["resume"]["name"];
$arr=explode('.', $org_filename);
$filename='resume'.time().'.'.$arr[count($arr)-1];
$target_dir = UPLOAD_PATH;
$target_file = $target_dir . basename($filename);
move_uploaded_file($_FILES["resume"]["tmp_name"], $target_file);
$_POST['resume']=$filename;
}
if(isset($_FILES) && $_FILES["cover_letter"]["name"]!=''){
$org_filename=$_FILES["cover_letter"]["name"];
$arr=explode('.', $org_filename);
$filename='cover_letter'.time().'.'.$arr[count($arr)-1];
$target_dir = UPLOAD_PATH;
$target_file = $target_dir . basename($filename);
move_uploaded_file($_FILES["cover_letter"]["tmp_name"], $target_file);
$_POST['cover_letter']=$filename;
}
if(isset($_FILES) && $_FILES["photo"]["name"]!=''){
$org_filename=$_FILES["photo"]["name"];
$arr=explode('.', $org_filename);
$filename='photo'.time().'.'.$arr[count($arr)-1];
$target_dir = UPLOAD_PATH;
$target_file = $target_dir . basename($filename);
move_uploaded_file($_FILES["photo"]["tmp_name"], $target_file);
$_POST['photo']=$filename;
}
$this->general_model->insert('apply_job',$_POST);
Using this code I try to send some data into my database as well as upload files in my server using post method. All data posted fine but files are not uploaded.
Showing error while uploading files
Undefined index: resume
Undefined index: cover_letter
Undefined index: photo
how to resolve this
Undefined index: resume
Undefined index: cover_letter
Undefined index: photo
It means there are no such records in the $_FILES array, which in turn means that files were not uploaded. It happens because those files contents is not extracted upon form serialization. For solution refer this answer.

Getting hold of which dynamically generated PHP variable has been clicked and display on the same page

I'm developing a messaging system and I have a list of items that are generated dynamically from a database using PHP.
All of these items have an associated message button and I need to know which one has been clicked and pass through the ID of this item to a message box that appears on the screen upon click of the message button.
I thought about using a form with hidden values to post, but this doesnt work as the page refreshes and I've used javascript to get the message box to popup too. document.getelementbyid also didn't help as the ID's of the items are generated dynamically. I read online I could do this using Ajax but couldn't get it to work with my code either.
Thanks in advance and apologies if this has already been asked but I've been searching for about half an hour and couldn't find any posts asking the same as my scenario.
<?php for ($j = 0; $j < $counter; $j++) { ?>
<div class="col-md-4 col-sm-6 item">
<div class="box">
<a href="itemdetails.php?id=<?php echo $itemIDDB[$j];?>">
<h3 class="name"><?php echo $itemNameDB[$j]?></h3>
<div class="row">
<div class="col-md-12"><img class="img-rounded profileimage" src="<?php echo $imageURLS[$j];?>"></div>
</div>
</a>
<div class="row">
<div class="col-md-6">
<p class="price"><?php echo "£" . $priceDB[$j]; ?></p>
</div>
<div class="col-md-6">
<p class="condition"><?php if ($conditionDB[$j] == 11) { echo "NEW"; } else { echo $conditionDB[$j]; } ?></p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<button class="btn btn-default btn-xs messagebutton" data-id="<?php echo $usernameDB[$i] ?>" type="button">message</button>
</div>
<div class="col-md-6">
<p class="username"><?php echo $usernameDB[$i] ?></p>
</div>
</div>
<p class="description"><?php echo $descriptionDB[$j]; ?></p>
</div>
</div>
<?php }
^^ Above is the code that generates each item and I need to pass the item ID to display instead of ' message username ' in the code below. All this code is in the same file.
<div id="messagenewuser">
<h3>Message username</h3>
<form method="post" class=".messagepopup">
<div class="form-group">
<textarea class="form-control" form="userreviewform" maxlength="50"></textarea>
</div>
<div class="form-group">
<button class="btn btn-default btn-xs" type="button" id="submitreview">send</button>
</div>
<input class="form-control hidden" type="text" name="tradeID">
</form>
</div>

Posting Form Data to Redirect Page

I have a contact form that I'm using phpmailer to send out the information that was entered in the form and once sent is redirected to another page. Which works great, now what I would like is to have all the information that is sent to the email address also posted on the redirect page (ie - target.php). I use 3 pages 1 for html, 1 for verify(js) and 1 (phpmailer) to send. I have read other questions here and I know if you put the redirect page in the action"target.php" on the form you can get the data, except I have to put action"appt.php" which is my phpmailer form. I have tried:
<body>
<div class="container">
<div class="row">
<h2>Form data</h2>
<hr/>
<p>This is a simple page showing the data you have just submitted</p>
<?php
$fullnameField = $_POST['fullname'];
echo $fullnameField;
$addressField = $_POST['address'];
echo $addressField;
?>
</div>
</div>
</body>
I put the code above on the target.php page.
This is what I get when redirected to target.php page:
Notice: Undefined index: fullname in C:\xampp\htdocs\appt\target.php on line 14
Notice: Undefined index: address in C:\xampp\htdocs\appt\target.php on line 16
Also tried taking off Field at the end of the $ and still get the same code.
Here is html page:
<form id="defaultForm" method="post" class="form-horizontal" action="appt.php">
<fieldset>
<!-- Form Name -->
<legend>Appointment Request</legend>
<!-- Full Name -->
<div class="form-group">
<label class="col-md-4 control-label">Full Name*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input name="fullname" placeholder="Your Full Name" class="form-control" type="text">
</div>
</div>
</div>
<!-- Address -->
<div class="form-group">
<label class="col-md-4 control-label" >Address*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-road"></i></span>
<input name="address" placeholder="Your Address" class="form-control" type="text">
</div>
</div>
</div>
<!-- City -->
<div class="form-group">
<label class="col-md-4 control-label">City*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
<input name="city" placeholder="Your City" class="form-control" type="text">
</div>
</div>
</div>
<!-- State Select -->
<div class="form-group">
<label class="col-md-4 control-label">State*</label>
<div class="col-md-6 selectContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
<select name="state" class="form-control selectpicker" >
<option value=" " >Please select your state</option>
<option>Ohio</option>
<option>Pennsylvania</option>
</select>
</div>
</div>
</div>
<!-- Zip Code -->
<div class="form-group">
<label class="col-md-4 control-label">Zip Code*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-globe"></i></span>
<input name="zip" placeholder="Your Zip Code" class="form-control" type="text">
</div>
</div>
</div>
<!-- Phone Number -->
<div class="form-group">
<label class="col-md-4 control-label">Phone*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
<input name="phone" placeholder="(330)123-1234" class="form-control" type="text">
</div>
</div>
</div>
<!-- Email -->
<div class="form-group">
<label class="col-md-4 control-label">E-mail*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input name="email" placeholder="Your Email Address" class="form-control" type="text">
</div>
</div>
</div>
<!-- Appt Reason Select -->
<div class="form-group">
<label class="col-md-4 control-label">Appt Reason*</label>
<div class="col-md-6 selectContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
<select name="reason" class="form-control selectpicker" >
<option value=" ">Select Your Appointment Reason</option>
<option>Roofing</option>
<option>Siding</option>
<option>Doors</option>
<option>Windows</option>
<option>Decking</option>
<option>Comfort Rooms</option>
<option>Kitchen</option>
</select>
</div>
</div>
</div>
<!-- Appt Date -->
<div class="form-group">
<label class="col-md-4 control-label">Appt Date*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group date" id="datepicker"> <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
<input name="apptDate" placeholder="Date You Would Like Appt" class="form-control" type="text">
</div>
</div>
</div>
<!-- Appt Time-->
<div class="form-group">
<label class="col-md-4 control-label">Appt Time*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group date" id="timepicker"> <span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
<input name="apptTime" placeholder="Time You Would Like Appt" class="form-control" type="text">
</div>
</div>
</div>
<!-- Contact Method Select -->
<div class="form-group">
<label class="col-md-4 control-label">Contact You*</label>
<div class="col-md-6 selectContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
<select name="method" class="form-control selectpicker" >
<option value=" ">Select Your Contact Method</option>
<option>Email</option>
<option>Phone</option>
</select>
</div>
</div>
</div>
<!-- Project Description -->
<div class="form-group">
<label class="col-md-4 control-label">Project Description*</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea class="form-control" name="comment" placeholder="Project Description" rows="5"></textarea>
</div>
</div>
</div>
<!-- Captcha -->
<div class="form-group">
<label class="col-md-4 control-label">Captcha</label>
<div class="col-md-6 inputGroupContainer">
<div id="captchaContainer"></div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-primary" >Send <span class="glyphicon glyphicon-send"></span></button>
</div>
</div>
</fieldset>
</form>
appt.php (phpmailer form):
<?php
session_start();
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
//Contact Form Data
$fullnameField = $_POST['fullname'];
$addressField = $_POST['address'];
$cityField = $_POST['city'];
$stateField = $_POST['state'];
$zipcodeField = $_POST['zip'];
$phoneField = $_POST['phone'];
$emailField = $_POST['email'];
$apptReasonField = $_POST['reason'];
$apptDateField = $_POST['apptDate'];
$apptTimeField = $_POST['apptTime'];
$methodField = $_POST['method'];
$commentsField = $_POST['comment'];
require 'mailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.aol.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username";
//Password to use for SMTP authentication
$mail->Password = "password";
//Set who the message is to be sent from
$mail->setFrom('sent from');
//Set who the message is to be sent to
$mail->addAddress('sent to');
//Set the subject line
$mail->Subject = 'Information For Appointment Wanted';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = <<<EOD
<br><p>Here is the information $fullnameField entered in your Appointment form.</p>
<br><hr><br>
<b>Name:</b> $fullnameField<hr><br>
<b>Address:</b> $addressField<hr><br>
<b>City:</b> $cityField<hr><br>
<b>State:</b> $stateField<hr><br>
<b>Zip Code:</b> $zipcodeField<hr><br>
<b>Phone #:</b> $phoneField<hr><br>
<b>E-mail:</b> $emailField<hr><br>
<b>Appointment Reason:</b> $apptReasonField<hr><br>
<b>Date Wanted For Appointment:</b> $apptDateField<hr><br>
<b>Time Wanted For Appointment:</b> $apptTimeField<hr><br>
<b>Best Way To Contact You:</b> $methodField<hr><br>
<b>Project Description:</b> $commentsField<hr><br>
EOD;
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
$_SESSION[fullname]=$fullnameField;
$_SESSION[address]=$addressField;
$_SESSION[city]=$cityField;
$_SESSION[state]=$stateField;
$_SESSION[zip]=$zipcodeField;
$_SESSION[phone]=$phoneField;
$_SESSION[email]=$emailField;
$_SESSION[reason]=$apptReasonField;
$_SESSION[apptDate]=$apptDateField;
$_SESSION[apptTime]=$apptTimeField;
$_SESSION[method]=$methodField;
$_SESSION[comment]=$commentsField;
header('Location: http://localhost/appt/target.php');
}
Here is the target.php
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<title>Thank You</title>
<link rel="stylesheet" href="css/bootstrap.css"/>
</head>
<body>
<div class="container">
<div class="row">
<p class="thank">Thank you <b><?php echo $_SESSION['fullname']; ?></b> for scheduling an appointment with U.S. Pride Home Specialists. We will be contacting you by the contact method you chose as soon as possible.</p>
</div>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8">Your Appointment Form Information</div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Name:</b> <?php echo $_SESSION['fullname']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Address:</b> <?php echo $_SESSION['address']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>City:</b> <?php echo $_SESSION['city']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>State:</b> <?php echo $_SESSION['state']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Zip Code:</b> <?php echo $_SESSION['zip']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Phone:</b> <?php echo $_SESSION['phone']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>E-mail:</b> <?php echo $_SESSION['email']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Appointment Reason:</b> <?php echo $_SESSION['reason']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Appointment Date Wanted:</b> <?php echo $_SESSION['apptDate']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Appointment Time Wanted:</b> <?php echo $_SESSION['apptTime']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Way You Wanted Contacted:</b> <?php echo $_SESSION['method']; ?></div><div class="col-md-2"></div>
</div>
<hr>
<div class="row">
<div class="col-md-2"></div><div class="col-md-8"><b>Project Description:</b> <?php echo $_SESSION['comment']; ?></div><div class="col-md-2"></div>
</div>
</div>
<?php
// remove all session variables
session_unset();
// destroy the session
session_destroy();
?>
</body>
</html>
You need to store your form data in a database table or session for persistence.
something like:
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
// BUILD $form_data here
$_SESSION['temp_form_data'] = serialize($form_data);
and after redirect just get data from session.
header('Location: http://localhost/appt/target.php');
}
And in the page that you show after redirect
in target.php
$form_data = unserialize($_SESSION['temp_form_data']);
// Use form data here
Another option would be to store it in database and retrieve it after redirect.
I do not suggest placing form data params and values over a url.

$_POST['projectSubmit'] not working

I'm tryig to echo a javascript after I hit the submit button to make sure that its working, but it only closes the modal and refreshes the page. What's wrong?
I also tried
'if($_POST[projectSubmit'] rather enclosing it on isset(). But it couldn't recognize the index 'projectSubmit'
<form action="" method="POST">
<div id="modal1" class="modal modal-fixed-footer" style="width:35%;">
<div class="modal-content">
<h4>Create Project</h4>
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">perm_identity</i>
<input type="text" name="projectName" class="validate">
<label for="projectName" class="">Project Name</label>
</div>
<div class="input-field col s12">
<i class="material-icons prefix">room</i>
<label for="projectLocation">Location</label>
<input type="text" name="projectLocation">
</div>
<div class="input-field col s12">
<label for="projectType">Project Type</label><br>
<input name="projectType" type="radio" value="Condominium" id="test1" />
<label for="test1" class="black-text">Condominium</label>
<input name="projectType" type="radio" value="Housing" id="test2" />
<label for="test2" class="black-text">Housing</label>
</div>
</div><!--ROW-->
</div>
<div class="modal-footer">
<input type="submit" name="projectSubmit"class="waves-effect waves-green btn-flat" value="s">
<button type="RESET" class="btn btn-flat">RESET</button>
</div>
</div>
<?php
if(isset($_POST['projectSubmit'])){
echo "<script type='text/javascript>alert('JUJU');</script>";
}
else{
echo "<script type='text/javascript>alert('xx');</script>";
}
?>
</form>
You have not complete the single quote after text/javascript.
Please update that as follows :
echo "<script type='text/javascript'>alert('JUJU');</script>";
and same as update the second echo :
echo "<script type='text/javascript'>alert('xx');</script>";
Incorrect java script tag (missing quote)
Your code
echo "<script type='text/javascript>alert('JUJU');</script>";
Correct tag
echo "<script type='text/javascript'>alert('JUJU');</script>";
for refer Can the <script> tag not be self closed?

Categories