Tagged: how to use sweet alert in codeigniter

Vue.js Alert popup-Dialog Box using PHP and CSS 0

Vue.js Alert popup-Dialog Box using PHP and CSS

Vue.js Alert popup-Dialog Box using PHP and CSS

In this Post We Will Explain About is Vue.js Alert popup-Dialog Box using PHP and CSS With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How To Create an Alert Message Box Example

In this post we will show you Best way to implement Vue.js Show JavaScript Alert Message Box on ng-click, hear for Fancy Alert and Confirm Box in Vue.js with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Create an Alert using Vue.js with PHP

In this Example,First of all Add or Include External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priority set.After that Include your relevant CSS Class.

Creating Simple Database

CREATE TABLE `students` (
  `studid` INT(11) NOT NULL AUTO_INCREMENT,
  `email` VARCHAR(60) NOT NULL,
  `password` VARCHAR(50) NOT NULL,
PRIMARY KEY(`studid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

style.css

.firstCorn{
	position:absolute;
	top:4px;
	right:6px;
}
.btnClose {
    margin-left: 15px;
    font-size: 18px;
    line-height: 20px;
	color: white;
    font-weight: bold;
    float: right;
    cursor: pointer;
    transition: 0.3s;
}
 
.btnClose:hover {
    color: #c30000;
}
.alert_danger {
    padding: 18px;
    background-color: #3d3d3d;
    color: white;
}
 
.alert_success {
    padding: 15px;
    background-color: #4CAF50;
    color: white;
}

index.php

<!DOCTYPE html>
<html>
<head>
	<title>Make simple an Alert using Vue.js with PHP</title>
3.3.7/css/bootstrap.min.css
2.5.10/vue.min.js
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="alert">
	<div class="firstCorn alert_danger" v-if="liveErr">
		<span class="btnClose" @click="dataclsMsg();">×</span>
		<span class="live glyphicon glyphicon-alert"></span> {{ getresMsg }}
	</div>
	<div class="firstCorn alert_success" v-if="liveSucc">
		<span class="btnClose" @click="dataclsMsg();">×</span>
		<span class="live glyphicon glyphicon-check-square-o"></span> {{ getresMsg }}
	</div>
	<div class="container">
		<h1 class="page-header text-center">Create an Alert using Vue.js with PHP</h1>
		<div class="col-md-4">
			<div class="live form-group">
				<label>Student Email:</label>
				<input type="text" class="form-control live" v-model="studentNew.email" v-on:keyup="checkKeyMonitor">
			</div>
			<div class="live form-group">
				<label>Password:</label>
				<input type="text" class="form-control live" v-model="studentNew.password" v-on:keyup="checkKeyMonitor">
			</div>
			<button class="btn btn-primary" @click="addStudent();"><span class="live glyphicon glyphicon-floppy-disk"></span> Save</button> <button class="btn btn-danger" @click="clearForm();"><span class="live glyphicon glyphicon-refresh"></span> Clear</button>
		</div>
		<div class="col-md-8">
			<table class="table">
				<thead>
					<th>student ID</th>
					<th>Student Email</th>
					<th>Student Password</th>
				</thead>
				<tbody>
					<tr v-for="student in students">
						<td>{{ student.studid }}</td>
						<td>{{ student.email }}</td>
						<td>{{ student.password }}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>
<script src="main.js"></script>
</body>
</html>

main.js

var main = new Vue({
	el: '#alert',
	data:{
		studentNew: {email: '', password: ''},
		alertMessage: false,
		liveSucc: false,
		liveErr: false,
		getresMsg: "",
		students: []
	},
 
	mounted: function(){
		this.getStudents();
	},
 
	methods:{
		checkKeyMonitor: function(event) {
       		if(event.key == "Enter"){
         		main.addStudent();
        	}
       	},
 
       	getStudents: function(){
			axios.post('do_action.php')
				.then(function(datares){
					main.students = datares.data.students;
				});
       	},
 
		addStudent: function(){
			var memberForm = main.saveFormData(main.studentNew);
			axios.post('do_action.php?do_action=add', memberForm)
				.then(function(datares){
					console.log(datares);
					if(datares.data.error){
						main.alertMessage = true;
						main.liveErr = true;
						main.liveSucc = false;
						main.getresMsg = datares.data.message;
						setTimeout(function(){
							main.dataclsMsg();
						},3000);
					}
					else{
						main.liveSucc = true;
						main.liveErr = false;
						main.alertMessage = true;
						main.getresMsg = datares.data.message;
						main.studentNew = {email: '', password:''};
						main.getStudents();
						setTimeout(function(){
							main.dataclsMsg();
						},3000);
					}
				});
		},
 
		saveFormData: function(obj){
			var form_data = new FormData();
			for(var key in obj){
				form_data.append(key, obj[key]);
			}
			return form_data;
		},
 
		dataclsMsg: function(){
			main.liveErr = false;
			main.liveSucc = false;
		},
 
		clearForm: function(){
			main.studentNew=main.studentNew = {email: '', password:''};
		}
 
 
 
	}
});

do_action.php

<?php
$db_conn = new mysqli("localhost", "username", "Password", "live24u");
 
if ($db_conn->connect_error) {
    die("Your Db Connection failed: " . $db_conn->connect_error);
}
 
$output = array('error' => false);
 
$do_action="show";
 
if(isset($_GET['do_action'])){
	$do_action=$_GET['do_action'];
}
 
if($do_action=='show'){
	$sql = "select * from students";
	$query = $db_conn->query($sql);
	$students = array();
 
	while($row = $query->fetch_array()){
		array_push($students, $row);
	}
 
	$output['students'] = $students;
}
 
if($do_action=='add'){
	$email=$_POST['email'];
	$password=$_POST['password'];
 
	if($email==''){
		$output['error']=true;
		$output['message']='Add student Failed. Student Name Empty.';
	}
	elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
		$output['error']=true;
		$output['message']='Add student Failed. Invalid Email Format';
	}
	elseif($password==''){
		$output['error']=true;
		$output['message']='Add student Failed. Password Empty.';
	}
	elseif(!preg_match("/^[a-zA-Z_1-9]*$/",$password)){
		$output['error']=true;
		$output['message']='Underscore as well as Special Characters  are not allowed in Password';
	}
	else{
		$sql="insert into students (email, password) values ('$email', '$password')";
		$query=$db_conn->query($sql);
 
		if($query){
			$output['message']='student Successfully Added';
		}
		else{
			$output['error']=true;
			$output['message']='Sorry !! Error in Adding Occured';
		}
 
	}
}
 
$db_conn->close();
header("Content-type: application/json");
echo json_encode($output);
die();
 
?>

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is Vue.js Show JavaScript Alert Message Box on ng-click with Example And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.