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




	Make simple an Alert using Vue.js with PHP
3.3.7/css/bootstrap.min.css
2.5.10/vue.min.js



× {{ getresMsg }}
× {{ getresMsg }}

Create an Alert using Vue.js with PHP

student ID Student Email Student Password
{{ student.studid }} {{ student.email }} {{ student.password }}

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

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.

Leave a Comment