I do this long years ago, but now, I don't remember and I can't put this working...
So, I have a form with action to another file.php, to send an email, and I want to put a sweet alert to tell people, okay your message has been sent...
Check the code in CONTACT.PHP
<link href="sweet/style.css" type="text/css" rel="stylesheet">
<link href="sweet/sweetalert.css" type="text/css" rel="stylesheet">
<script src="sweet/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="sweet/sweetalert.min.js" type="text/javascript"></script>
<script type='text/javascript'>
$( document ).ready(function() {
// Show image
$("#but3").click(function(){
var message = $("#message").val();
var title = $("#title").val();
if(message == "Welcome"){
message = "Welcome";
}
if(title == "Welcome"){
title = "Welcome";
}
swal({
title: title,
text: message,
imageUrl: "logo.png"
});
});
// Timer
$("#but4").click(function(){
var message = $("#message").val();
var title = $("#title").val();
if(message == ""){
message = "Your message";
}
if(title == ""){
title = "Your message";
}
message += "(close after 2 seconds)";
swal({
title: title,
text: message,
timer: 2000,
showConfirmButton: false
});
});
});
</script>
<!-- main-container -->
<div class="container main-container">
<div class="col-md-6">
<form action="envia.php" name="envia" id="envia" method="post">
<div class="row">
<div class="col-md-6">
<div class="input-contact">
<input type="text" name="nome" id="nome" required>
<span>Nome</span>
</div>
</div>
<div class="col-md-6">
<div class="input-contact">
<input type="text" id="email" name="email" required>
<span>Email</span>
</div>
</div>
<div class="col-md-12">
<div class="input-contact">
<input type="text" name="assunto" id="assunto" required>
<span>Assunto</span>
</div>
</div>
<div class="col-md-12">
<div class="textarea-contact">
<textarea name="menssagem" id="mensagem" required></textarea>
<span>Mensagem</span>
</div>
</div>
<div class="col-md-12">
<input type="submit" name="enviar" value="enviar" class="btn btn-box">
</div>
</div>
</form>
<table>
<tr><td> THIS SMALL FORM ITS JUST FOR SHOW SWEET ALERT </TD></TR>
<tr>
<td>Title</td>
<td><input type='text' value='Title text' id='title'></td>
</tr>
<tr>
<td>Message</td>
<td><input type='text' value='Your message' id='message'></td>
</tr>
<tr>
<td colspan='2'>
<input type='button' value='Alert with image' id='but4'>
</td>
</tr>
</table>
</div>
--
<!-- main-container -->
<div class="container main-container">
<div class="col-md-6">
<form action="envia.php" name="envia" id="envia" method="post">
<div class="row">
<div class="col-md-6">
<div class="input-contact">
<input type="text" name="nome" id="nome" required>
<span>Nome</span>
</div>
</div>
<div class="col-md-6">
<div class="input-contact">
<input type="text" id="email" name="email" required>
<span>Email</span>
</div>
</div>
<div class="col-md-12">
<div class="input-contact">
<input type="text" name="assunto" id="assunto" required>
<span>Assunto</span>
</div>
</div>
<div class="col-md-12">
<div class="textarea-contact">
<textarea name="menssagem" id="mensagem" required></textarea>
<span>Mensagem</span>
</div>
</div>
<div class="col-md-12">
<input type="submit" name="enviar" value="enviar" class="btn btn-box">
</div>
</div>
</form>
<table>
<tr><td> THIS SMALL FORM ITS JUST FOR SHOW SWEET ALERT </TD></TR>
<tr>
<td>Title</td>
<td><input type='text' value='Title text' id='title'></td>
</tr>
<tr>
<td>Message</td>
<td><input type='text' value='Your message' id='message'></td>
</tr>
<tr>
<td colspan='2'>
<input type='button' value='Alert with image' id='but4'>
</td>
</tr>
</table>
</div>
THE FILE ENVIA.PHP
$nomeremetente = $_POST['nome'];
$emailremetente = trim($_POST['email']);
$emaildestinatario = 'info#mydomain.pt';// Digite seu e-mail aqui, lembrando que o e-mail deve estar em seu servidor web
$assunto = $_POST['assunto'];
$mensagem = $_POST['mensagem'];
/* Montando a mensagem a ser enviada no corpo do e-mail. */
$mensagemHTML = '
<strong>Formulário de Contato</strong>
<p><b>Nome:</b> '.$nomeremetente.' <p>
<b>E-Mail:</b> '.$emailremetente.' <p>
<b>Assunto:</b> '.$assunto.' <p>
<b>Mensagem:</b> '.$mensagem.'</p>
<hr>';
// O remetente deve ser um e-mail do seu domínio conforme determina a RFC 822.
// O return-path deve ser ser o mesmo e-mail do remetente.
$headers = "MIME-Version: 1.1\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: $emailremetente\r\n";
// remetente
$headers .= "Return-Path: $emaildestinatario \r\n";
// return-path
$envio = mail($emaildestinatario, $assunto, $mensagemHTML, $headers);
if($envio)
echo "<script>location.href='contact.php'</script>";// Página que será redirecionada
I have tried so many ways, and I just reset everything and now I don't know what to do.........
Edited to the full code fix
contact.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Box personal portfolio Template</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="ionicons/css/ionicons.min.css" rel="stylesheet" />
<link rel="icon" href="img/fav.png" type="image/x-icon" />
<!-- main css -->
<link href="css/style.css" rel="stylesheet" />
<!-- Sweetalert -->
<!-- <link href="sweet/style.css" type="text/css" rel="stylesheet" /> -->
<link href="sweet/sweetalert.css" type="text/css" rel="stylesheet" />
<script src="sweet/sweetalert.min.js" type="text/javascript"></script>
<!-- modernizr -->
<script src="js/modernizr.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Preloader -->
<div id="preloader">
<div class="pre-container">
<div class="spinner">
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div>
</div>
</div>
<!-- end Preloader -->
<div class="container-fluid">
<!-- box-header -->
<header class="box-header">
<div class="box-logo">
<a href="index.html"
><img src="img/logo.png" width="80" alt="Logo"
/></a>
</div>
<!-- box-nav -->
<a class="box-primary-nav-trigger" href="#0">
<span class="box-menu-text">Menu</span
><span class="box-menu-icon"></span>
</a>
<!-- box-primary-nav-trigger -->
</header>
<!-- end box-header -->
<!-- nav -->
<nav>
<ul class="box-primary-nav">
<li class="box-label">About me</li>
<li>Intro</li>
<li>About me</li>
<li>services</li>
<li>portfolio</li>
<li>
contact me
<i class="ion-ios-circle-filled color"></i>
</li>
<li class="box-label">Follow me</li>
<li class="box-social">
<i class="ion-social-facebook"></i>
</li>
<li class="box-social">
<i class="ion-social-instagram-outline"></i>
</li>
<li class="box-social">
<i class="ion-social-twitter"></i>
</li>
<li class="box-social">
<i class="ion-social-dribbble"></i>
</li>
</ul>
</nav>
<!-- end nav -->
</div>
<!-- top bar -->
<div class="top-bar">
<h1>contact Me</h1>
<p>Home / Contact Me</p>
</div>
<!-- end top bar -->
<!-- main-container -->
<div class="container main-container">
<div class="col-md-6">
<form name="envia" action="#" id="envia">
<div class="row">
<div class="col-md-6">
<div class="input-contact">
<input type="text" name="nome" id="nome" required />
<span>Nome</span>
</div>
</div>
<div class="col-md-6">
<div class="input-contact">
<input type="text" id="email" name="email" required />
<span>Email</span>
</div>
</div>
<div class="col-md-12">
<div class="input-contact">
<input type="text" name="assunto" id="assunto" required />
<span>Assunto</span>
</div>
</div>
<div class="col-md-12">
<div class="textarea-contact">
<textarea name="menssagem" id="mensagem" required></textarea>
<span>Mensagem</span>
</div>
</div>
<div class="col-md-12">
<input
id="submit"
type="submit"
name="enviar"
value="enviar"
class="btn btn-box"
/>
</div>
</div>
</form>
</div>
<div class="col-md-6">
<h3 class="text-uppercase">Entre em contacto</h3>
<h5>Pedidos orçamento e esclarecimento de dúvidas.</h5>
<div class="h-30"></div>
<p>
<br />Poderá usar este formulário para esclarecimento de dúvidas ou
pedido de orçamento, para pedidos de orçamento deverá indicar o mais
claro possivel o que pretende.
</p>
<div class="contact-info">
<p><i class="ion-android-call"></i>911729199</p>
<p><i class="ion-ios-email"></i>info#obruno.pt</p>
</div>
</div>
</div>
<!-- end main-container -->
<!-- footer -->
<footer>
<div class="container-fluid">
<p class="copyright">© Box Portfolio 2016</p>
</div>
</footer>
<!-- end footer -->
<!-- back to top -->
<i class="ion-android-arrow-up"></i>
<!-- end back to top -->
<!-- jQuery -->
<script src="js/jquery-2.1.1.js"></script>
<!-- plugins -->
<script src="js/bootstrap.min.js"></script>
<script src="js/menu.js"></script>
<script src="js/animated-headline.js"></script>
<script src="js/isotope.pkgd.min.js"></script>
<!-- custom script -->
<script src="js/custom.js"></script>
<script>
// This will prevent the default button action and the page won't refresh
document.querySelector("#submit").addEventListener(
"click",
function (event) {
process();
},
false
);
// This will make a post request to your php file
function process() {
// Getting the inputs
var message = document.getElementById("mensagem").value;
var email = document.getElementById("email").value;
var subject = document.getElementById("assunto").value;
var name = document.getElementById("nome").value;
// Some data validation to see if the user have filled the required fields
if (message && email && subject && name) {
event.preventDefault();
// Setting the AJAX request handler
var xmlhttp = new XMLHttpRequest();
// Waiting for a response
xmlhttp.onreadystatechange = function () {
// If the response is 200 aka "OK"
if (this.readyState == 4 && this.status == 200) {
// Show your success alert here
swal({
title: "Message Sent!",
text: "Thank you for contacting us.",
timer: 2000,
showConfirmButton: false,
});
document.getElementById("envia").reset();
return;
}
};
// Setting the request type and data to be sent
xmlhttp.open("POST", "envia.php", true);
xmlhttp.setRequestHeader(
"Content-type",
"application/x-www-form-urlencoded"
);
xmlhttp.send(
"nome=" +
name +
"&email=" +
email +
"&assunto=" +
subject +
"&mensagem=" +
message
);
} else {
// Alert the user to fill the required fields
console.log("please fill all required fields");
return;
}
}
</script>
</body>
</html>
envia.php
<?php
$nomeremetente = $_POST['nome'];
$emailremetente = $_POST['email'];
$emaildestinatario = 'info#mydomain.pt';
$assunto = $_POST['assunto'];
$mensagem = $_POST['mensagem'];
$content = '<strong>Formulário de Contato</strong><p><b>Nome:</b> ' . $nomeremetente . ' <p><b>E-Mail:</b> ' . $emailremetente . ' <p><b>Assunto:</b> ' . $assunto . ' <p><b>Mensagem:</b> ' . $mensagem . '</p><hr>';
$headers = array(
'From' => $emailremetente,
'Reply-To' => $emaildestinatario,
'MIME-Version' => '1.1',
'Content-type' => 'text/html;charset=UTF-8',
'X-Mailer' => 'PHP/' . phpversion()
);
if (isset($nomeremetente) && isset($emailremetente) && isset($emaildestinatario) && isset($assunto) && isset($mensagem) && isset($content)) {
mail($emaildestinatario, $assunto, $content, $headers);
echo "SUCCESS";
http_response_code(200);
} else {
echo "FAILED";
http_response_code(404);
}
Take note that I have added already the sweet alert you can go ahead and customize the message to display after email success
NB: Don't forget to change the email that you're going to receive email on to one on your domain or the emails would end up not getting sent or in your spam
Related
I used Tecite for my contact form and am trying to get my form to work but it is coming up with an error message every time that is saying:
"An errr occurred while processing the form."
The staff... and it goes on as a generic error message.
Im not sure what I am missing in my code but would love some help!!
I have posted my code below, one being the contact.html and the other the formmail php code.
php form
---contact.html---
Haus of Originals
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="Haus of Originals Website">
<link href="css/style_contact.css" rel="stylesheet" type="text/css" />
<link rel="icon" type="image/png" href="images/h_favicon2.png">
<!-- Script -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<!-- Responsive and mobile friendly stuff -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Haus of Originals
</div>
<div class="button_container" id="toggle">
<span class="top"></span>
<span class="middle"></span>
<span class="bottom"></span>
</div>
<div class="overlay" id="overlay">
<nav class="overlay-menu">
<ul>
<li><a class="one" href="home.html" title="Home">Home</a></li>
<li><a class="one" href="about.html" title="About">About</a></li>
<li><a class="one active" href="contact.html" title="Contact">Contact</a></li>
</ul>
</nav>
</div>
<!-- Header Gif -->
<div class="section banner">
<h4>
We are building brands that we want to be apart of, welcome home. </h4>
</div>
<!-- Header Gif End -->
<div class="section group">
<img src="images/rtt.jpg" alt="walllogo">
</div>
<div class="section group three">
<div class="column span_1_of_2">
<h5>Contact</h5>
<h6> Haus of Originals<br>
28 Intrepid Drive <br>
Bozeman, Montana 59718
<br>
<br>
651.470.6511<br>
406.459.5954
<br> <br>
<a class="three" href="mailto:info#hausoforiginals.com">info#hausoforiginals.com</a>
</h6>
</div>
<div class="column span_2_of_2">
</div>
</div>
<div class="section group four">
<section class="contact-wrap">
<!--Form Action Needs to point to where you have uploaded the formail.php file-->
<form method="post" action="http://www.hausoforiginals.com/formmail/formmail.php" name="ContactForm" class="contact-form">
<!-- Keep this line it's base settings to check and send the form -->
<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" />
<!-- This sets where the email is sent to -->
<input type="hidden" name="recipients" value="info#hausoforiginals.com" />
<!-- This sets the fields to be required. -->
<input type="hidden" name="required" value="EmailAddress:Your email address,FirstName:Your name,Message: Your message" />
<div class="col-sm-6">
<div class="input-block">
<label for="FirstName">First Name</label>
<input type="text" name="FirstName" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="input-block">
<label for="EmailAddress">Email</label>
<input type="email" name="EmailAddress" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="input-block">
<label for="MessageSubject">Subject</label>
<input type="text" name="MessageSubject" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="input-block textarea">
<label for="Message">Spit it Out</label>
<textarea rows="3" name="Message" class="form-control"></textarea>
</div>
</div>
<div class="col-sm-12">
<input type="submit" value="Submit" class="square-button">Send It
</div>
</form>
</section>
</div>
<div class="section group two">
<div class="col spanfooter_1_of_3">
<img class="logoone" src="images/h_logo_hp.jpg" alt="logo">
</div>
<div class="col spanfooter_2_of_3">
<h2>Handles </h2>
<p>Instagram</p>
<p>Twitter </p>
<p>Facebook </p>
<b>back to top</b>
</div>
<div class="col spanfooter_3_of_3">
<h2>Get in Touch</h2>
<p> 651.470.6511 <b>|</b> 406.459.5954 </p><br>
<a class="two" href="mailto:info#hausoforiginals.com"><b>info#hausoforiginals.com</b></a>
<br>
<p>
2017 © All Rights Reserved
</p>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(window).bind('scroll', function() {
checkScrollPos();
});
checkScrollPos();
$('.toTopLink').bind('click', function() {
$('html, body').animate({
scrollTop: 0
}, $(window).scrollTop() / 3);
return false;
});
});
function checkScrollPos() {
if ($(window).scrollTop() > 600) {
$('.toTopLink').fadeIn(1000);
} else {
$('.toTopLink').fadeOut(1000);
}
}
$(document).ready(function() {
//material contact form
$('.contact-form').find('.form-control').each(function() {
var targetItem = $(this).parent();
if ($(this).val()) {
$(targetItem).find('label').css({
'top': '10px',
'fontSize': '14px'
});
}
})
$('.contact-form').find('.form-control').focus(function() {
$(this).parent('.input-block').addClass('focus');
$(this).parent().find('label').animate({
'top': '10px',
'fontSize': '14px'
}, 300);
})
$('.contact-form').find('.form-control').blur(function() {
if ($(this).val().length == 0) {
$(this).parent('.input-block').removeClass('focus');
$(this).parent().find('label').animate({
'top': '25px',
'fontSize': '18px'
}, 300);
}
})
});
$('#toggle').click(function() {
$(this).toggleClass('active');
$('#overlay').toggleClass('open');
});
</script>
I am new to php, i have an affiliate script, in the add campaign page when i fill the form and submit the form it says "Campaign Added" but the form data was not saved in database,
My Add Campaign Form
<?php
session_start();
if(isset($_SESSION['myadminusername']))
{
$myusername = $_SESSION['myadminusername'];
include '../config.php';
header( 'Content-Type: text/html; charset=utf-8' );
}
else
{
echo"<script type='text/javascript'>
window.location.href='login.php';
</script>";
}
if( isset($_POST['text']) )
{
mysql_query("Insert into link values ('', '".addslashes($_POST['text'])."', '".addslashes($_POST['caption'])."', '".addslashes($_POST['description'])."', '".$_POST['img']."', '".$_POST['site_us_pc']."', '".$_POST['site_oth_pc']."', '".$_POST['site_us_mob']."', '".$_POST['site_oth_mob']."', '".$_POST['status']."', '".$_POST['catname']."', '".$_POST['us_cpc']."', '".$_POST['uk_cpc']."', '".$_POST['au_cpc']."', '".$_POST['in_cpc']."', '".$_POST['oth_cpc']."', '".$_POST['pak_cpc']."', '".$_POST['star']."', '0')");
echo"<script type='text/javascript'>
alert('Campaign Added');
</script>";
}
?>
<!doctype html>
<!--[if lte IE 9]> <html class="lte-ie9" lang="en"> <![endif]-->
<!--[if gt IE 9]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Remove Tap Highlight on Windows Phone IE -->
<meta name="msapplication-tap-highlight" content="no"/>
<link rel="icon" type="image/png" href="assets/img/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="assets/img/favicon-32x32.png" sizes="32x32">
<title>Altair Admin v2.0.0</title>
<!-- uikit -->
<link rel="stylesheet" href="bower_components/uikit/css/uikit.almost-flat.min.css" media="all">
<!-- flag icons -->
<link rel="stylesheet" href="assets/icons/flags/flags.min.css" media="all">
<!-- altair admin -->
<link rel="stylesheet" href="assets/css/main.min.css" media="all">
<!-- matchMedia polyfill for testing media queries in JS -->
<!--[if lte IE 9]>
<script type="text/javascript" src="bower_components/matchMedia/matchMedia.js"></script>
<script type="text/javascript" src="bower_components/matchMedia/matchMedia.addListener.js"></script>
<![endif]-->
</head>
<?php include 'head.php'; ?>
<div id="page_content">
<div id="page_content_inner">
<h3 class="heading_b uk-margin-bottom">Blank Page</h3>
<div class="md-card">
<div class="md-card-content">
<div class="uk-grid" data-uk-grid-margin>
<div class="uk-width-1-1">
<form method="post" action="campaign_add.php">
<div class="form-group">
<label>Campaign Title</label>
<input class="md-input" name="text" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Suggested Caption</label>
<input class="md-input" name="caption" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Campaign Image Link</label>
<input class="md-input" name="img" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Campaign Description</label>
<input class="md-input" name="description" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Campaign US PC Link</label>
<input class="md-input" name="site_us_pc" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Campaign Other PC Link</label>
<input class="md-input" name="site_oth_pc" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Campaign US Mob Link</label>
<input class="md-input" name="site_us_mob" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Campaign Other Mob link</label>
<input class="md-input" name="site_oth_mob" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Campaign Status</label>
<select name="status">
<option value="enable">Enable</option>
<option value="disable">Disable</option>
</select>
</div>
<br>
<br>
<div class="form-group">
<label>Campaign Category</label>
<select name="catname">
<?php
$results = mysql_query("Select * from link_cat");
while ($row = mysql_fetch_array($results))
{
echo'<option value="'.$row['id'].'">'.$row['catname'].'</option>';
}
?>
</select>
</div>
<br>
<br>
<div class="form-group">
<label>US Pay per click (INR)</label>
<input class="md-input" name="us_cpc" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>UK Pay per click (INR)</label>
<input class="md-input" name="uk_cpc" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Australia Pay per click (INR)</label>
<input class="md-input" name="au_cpc" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>India Pay per click (INR)</label>
<input class="md-input" name="in+cpc" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Pakistan Pay per click (INR)</label>
<input class="md-input" name="pak_cpc" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Other Pay per click (INR)</label>
<input class="md-input" name="oth_cpc" type="text">
</div>
<br>
<br>
<div class="form-group">
<label>Star</label>
<select name="star">
<option value="false">No</option>
<option value="true">Yes</option>
</select>
</div>
<br>
<br>
<div class="form-group">
<input class="md-btn md-btn-primary" value="Add" type="submit">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- google web fonts -->
<script>
WebFontConfig = {
google: {
families: [
'Source+Code+Pro:400,700:latin',
'Roboto:400,300,500,700,400italic:latin'
]
}
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
</script>
<!-- common functions -->
<script src="assets/js/common.min.js"></script>
<!-- uikit functions -->
<script src="assets/js/uikit_custom.min.js"></script>
<!-- altair common functions/helpers -->
<script src="assets/js/altair_admin_common.min.js"></script>
<script>
$(function() {
// enable hires images
altair_helpers.retina_images();
// fastClick (touch devices)
if(Modernizr.touch) {
FastClick.attach(document.body);
}
});
</script>
<div id="style_switcher">
<div id="style_switcher_toggle"><i class="material-icons"></i></div>
<div class="uk-margin-medium-bottom">
<h4 class="heading_c uk-margin-bottom">Colors</h4>
<ul class="switcher_app_themes" id="theme_switcher">
<li class="app_style_default active_theme" data-app-theme="">
<span class="app_color_main"></span>
<span class="app_color_accent"></span>
</li>
<li class="switcher_theme_a" data-app-theme="app_theme_a">
<span class="app_color_main"></span>
<span class="app_color_accent"></span>
</li>
<li class="switcher_theme_b" data-app-theme="app_theme_b">
<span class="app_color_main"></span>
<span class="app_color_accent"></span>
</li>
<li class="switcher_theme_c" data-app-theme="app_theme_c">
<span class="app_color_main"></span>
<span class="app_color_accent"></span>
</li>
<li class="switcher_theme_d" data-app-theme="app_theme_d">
<span class="app_color_main"></span>
<span class="app_color_accent"></span>
</li>
<li class="switcher_theme_e" data-app-theme="app_theme_e">
<span class="app_color_main"></span>
<span class="app_color_accent"></span>
</li>
<li class="switcher_theme_f" data-app-theme="app_theme_f">
<span class="app_color_main"></span>
<span class="app_color_accent"></span>
</li>
<li class="switcher_theme_g" data-app-theme="app_theme_g">
<span class="app_color_main"></span>
<span class="app_color_accent"></span>
</li>
</ul>
</div>
<div class="uk-visible-large">
<h4 class="heading_c">Sidebar</h4>
<p>
<input type="checkbox" name="style_sidebar_mini" id="style_sidebar_mini" data-md-icheck />
<label for="style_sidebar_mini" class="inline-label">Mini Sidebar</label>
</p>
</div>
</div>
<script>
$(function() {
var $switcher = $('#style_switcher'),
$switcher_toggle = $('#style_switcher_toggle'),
$theme_switcher = $('#theme_switcher'),
$mini_sidebar_toggle = $('#style_sidebar_mini');
$switcher_toggle.click(function(e) {
e.preventDefault();
$switcher.toggleClass('switcher_active');
});
$theme_switcher.children('li').click(function(e) {
e.preventDefault();
var $this = $(this),
this_theme = $this.attr('data-app-theme');
$theme_switcher.children('li').removeClass('active_theme');
$(this).addClass('active_theme');
$('body')
.removeClass('app_theme_a app_theme_b app_theme_c app_theme_d app_theme_e app_theme_f app_theme_g')
.addClass(this_theme);
if(this_theme == '') {
localStorage.removeItem('altair_theme');
} else {
localStorage.setItem("altair_theme", this_theme);
}
});
// change input's state to checked if mini sidebar is active
if((localStorage.getItem("altair_sidebar_mini") !== null && localStorage.getItem("altair_sidebar_mini") == '1') || $('body').hasClass('sidebar_mini')) {
$mini_sidebar_toggle.iCheck('check');
}
// toggle mini sidebar
$mini_sidebar_toggle
.on('ifChecked', function(event){
$switcher.removeClass('switcher_active');
localStorage.setItem("altair_sidebar_mini", '1');
location.reload(true);
})
.on('ifUnchecked', function(event){
$switcher.removeClass('switcher_active');
localStorage.removeItem('altair_sidebar_mini');
location.reload(true);
});
// hide style switcher
$document.on('click keyup', function(e) {
if( $switcher.hasClass('switcher_active') ) {
if (
( !$(e.target).closest($switcher).length )
|| ( e.keyCode == 27 )
) {
$switcher.removeClass('switcher_active');
}
}
});
if(localStorage.getItem("altair_theme") !== null) {
$theme_switcher.children('li[data-app-theme='+localStorage.getItem("altair_theme")+']').click();
}
});
</script></body>
</html>
Database Table Column List screen short
You have to change:
<input class="md-input" name="in+cpc" type="text">
to:
<input class="md-input" name="in_cpc" type="text">
and to check the return value:
if(isset($_POST['text']))
{
$returnValue = mysql_query("Insert into link
values ('',
'".addslashes($_POST['text'])."',
'".addslashes($_POST['caption'])."',
'".addslashes($_POST['description'])."',
'".$_POST['img']."',
'".$_POST['site_us_pc']."',
'".$_POST['site_oth_pc']."',
'".$_POST['site_us_mob']."',
'".$_POST['site_oth_mob']."',
'".$_POST['status']."',
'".$_POST['catname']."',
'".$_POST['us_cpc']."',
'".$_POST['uk_cpc']."',
'".$_POST['au_cpc']."',
'".$_POST['in_cpc']."',
'".$_POST['oth_cpc']."',
'".$_POST['pak_cpc']."',
'".$_POST['star']."',
'0')");
if ($returnValue === FALSE) $message = 'Failure: '.mysql_error();
else $message = 'Campaign Added';
echo"<script type='text/javascript'>
alert('$message');
</script>";
}
I cannot garantee I found all errors. You might find my layout a bit strange, but I can read this much better.
NOTE: The mysql extension of PHP is depricated, and never insert user input directly in a query.
I'm having problem to get my different div from my php function
This is the code
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
require_once("./include/membersite_config.php");
if (!$fgmembersite->CheckLogin()) {
$fgmembersite->RedirectToURL("index.php");
exit;
}
if (isset($_POST['submitted'])) {
if($fgmembersite->ChangePassword()){
echo '<div id="ajaxDivOk">';
sleep(3);
$fgmembersite->RedirectToURL("index.php");
}
else{
echo '<div id="ajaxDivErro">';
sleep(3);
}
}
?>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>EBSPMA PAAD</title>
<link href="css/styles.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/modernizr.js?cb=2.2.3.2085"></script>
<script type="text/javascript">
</script>
</head>
<body>
<header role="banner" class="main-header">
<!-- MAIN HEADER -->
<div class="main-header-body">
<div class="container-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-xs-3">
<h2>
PAAD-GesDocente</h2>
</div>
<div class="col-xs-4 col-xs-offset-1 main-header-title">
<p class="sizeToggle" >Mudar Password</p>
</div>
</div>
</div>
</div>
</div>
</header><section class="content">
<div class="grid">
<div class="box">
<form name="changepwd" id="loginForm" action='<?php echo $fgmembersite->GetSelfScript(); ?>' method="POST">
<input type="hidden" name='submitted' id='submitted'/>
<input type="hidden" name="path" value="painelAdquirente.action"/>
<div>
<p><b><font color="red">A sua password deve ser alterada!</font></b></p></div>
<div class="icon-input">
<label for="password"></label>
<div class="input password">
<i class="fa fa-lock"></i>
<input type="password" name="oldpwd" id="oldpwd" placeholder="Senha antiga">
</div>
</div>
<br>
<div class="icon-input">
<label for="password"></label>
<div class="input password">
<i class="fa fa-lock"></i>
<input type="password" name="newpwd" id="newpwd" placeholder="Senha nova">
</div>
<input type="hidden" name="email" id="email" value="<?php echo $fgmembersite->UserEmail(); ?>">
</div>
<br>
<input type="submit" id="sbmtLogin" class="sa-btn1" value="Mudar">
</form>
</div>
<div class="form-group">
<div id="ajaxDivOk" name="ajaxDivOk" style="display:none" class="alert alert-success">Modificado com sucesso...Faça login novamente</div>
</div>
<div class="form-group">
<div id="ajaxDivErro" name="ajaxDivErro" style="display:none" class="alert alert-danger">Opss....Erro, tente mais tarde</div>
</div>
</div>
</section>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script src="js/plugins.js?cb=2.2.3.2085"></script>
</body>
</html>
The div is not show but in fiddler i get
<div id="ajaxDivOk">
So the php function is working properly since the password is changed and i should have the div
Any help please?
Thanks
You can set which notification you want to show up when you do your checks at the beginning, and then display the appropriate one in the following HTML. You can handle the redirect the same way.
if (isset($_POST['submitted'])) {
if ($fgmembersite->ChangePassword()) {
$redirect = '<meta http-equiv="refresh" content="3; url=index.php" />';
$notice = '<div id="ajaxDivOk" name="ajaxDivOk" class="alert alert-success">
Modificado com sucesso...Faça login novamente</div>';
} else {
$redirect = '';
$notice = '<div id="ajaxDivErro" name="ajaxDivErro" class="alert alert-danger">
Opss....Erro, tente mais tarde</div>';
}
}
Then in the <head> of your document...
<head>
<?php if isset($redirect) echo $redirect; ?>
...
And later where you are displaying the notifications:
<div class="form-group">
<?php if isset($notice) echo $notice; ?>
</div>
I'm having another problem with this code. I have tried different ways but no success.
if (isset($_POST['submitted'])) {
if($fgmembersite->ChangePassword()){
echo '<div id="ajaxDivOk">Password alterada com sucesso</div>';
sleep(2);
$fgmembersite->RedirectToURL("index.php");
}
echo '<div id="ajaxDivErro">A mudança de password não foi efetuadada....tente mais tarde</div>';
sleep(2);
}
In the debugger, I get the echo...but not in the main page.
This is my main page:
<?PHP
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
require_once("./include/membersite_config.php");
if (!$fgmembersite->CheckLogin()) {
$fgmembersite->RedirectToURL("index.php");
exit;
}
if (isset($_POST['submitted'])) {
if($fgmembersite->ChangePassword()){
echo '<div id="ajaxDivOk">Password alterada com sucesso</div>';
sleep(2);
$fgmembersite->RedirectToURL("index.php");
}
echo '<div id="ajaxDivErro">A mudança de password não foi efetuadada....tente mais tarde</div>';
sleep(2);
}
$email = $fgmembersite->UserEmail();
?>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>EBSPMA Atividades</title>
<link href="css/styles.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/modernizr.js?cb=2.2.3.2085"></script>
<script type="text/javascript">
</script>
</head>
<body>
<header role="banner" class="main-header">
<!-- MAIN HEADER -->
<div class="main-header-body">
<div class="container-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-xs-3">
<h2>EBSPMA PAAD</h2>
</div>
<div class="col-xs-4 col-xs-offset-1 main-header-title">
<p class="sizeToggle" >Mudar Password</p>
</div>
</div>
</div>
</div>
</div>
</header><section class="content">
<div class="grid">
<div class="box">
<form name="changepwd" id="loginForm" action='<?php echo $fgmembersite->GetSelfScript(); ?>' method="POST">
<input type="hidden" name='submitted' id='submitted'/>
<input type="hidden" name="path" value="painelAdquirente.action"/>
<div>
<p><b><font color="red">A sua password deve ser alterada!</font></b></p></div>
<div class="icon-input">
<label for="password"></label>
<div class="input password">
<i class="fa fa-lock"></i>
<input type="password" name="oldpwd" id="oldpwd" placeholder="Senha antiga">
</div>
</div>
<br>
<div class="icon-input">
<label for="password"></label>
<div class="input password">
<i class="fa fa-lock"></i>
<input type="password" name="newpwd" id="newpwd" placeholder="Senha nova">
</div>
<input type="hidden" name="email" id="email" value="<?php echo $email; ?>">
</div>
<br>
<input type="submit" id="sbmtLogin" class="sa-btn1" value="Mudar">
</form>
</div>
<div class="form-group">
<div id="ajaxDivOk" style="display:none" class="alert alert-success">Aqui</div>
</div>
<div class="form-group">
<div id="ajaxDivErro" style="display:none" class="alert alert-danger"></div>
</div>
</div>
</section>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script src="js/plugins.js?cb=2.2.3.2085"></script>
</body>
</html>
The function is working since I receive in my debugger the sentence
<div class="alert alert-success">Verifique o seu mail....Obrigado</div>
So what's wrong?
UPDATE:
I'm still having a problem: now I have this error:
Uncaught ReferenceError: checkMudaPass is not defined
The function is:
<script type="text/javascript">
function checkMudaPass(){
var res = "<?php echo $result; ?>";
console.log(res);
if(res === "1"){
document.getElementById('ajaxDivOk').style.display = "block";
document.getElementById('ajaxDivOk').innerHTML = "A mudança de password foi efetuada....Verifique o seu email";
}else{
document.getElementById('ajaxDivErro').style.display = "block";
document.getElementById('ajaxDivErro').innerHTML = "A mudança de password não foi efetuada";
}
setTimeout(function(){
window.location='index.php';
}, 5000);
};
</script>
<input type="submit" id="submitted" name="submitted" class="sa-btn1" value="Mudar" onclick="checkMudaPass()">
I'm doing a registration page. It requires the name, password, email, gender, nationality, date of birth and other things.
I did the registration and it was good. But I need to add the validation and this is what I could do so far:
<?php include("config.php"); ?>
<!DOCTYPE html>
<html lang="en">
<!-- CSS -->
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
<link type="text/css" href="css/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<!-- JavaScript -->
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<script src="js/validation.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$('#datepicker').datepicker({
dateFormat:'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '-90:+0',
maxDate: '+0'
});
});
</script>
</head>
<head>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.4.2.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_italic_600.font.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_italic_400.font.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_400.font.js"></script>
<!--[if lt IE 9]>
<script type="text/javascript" src="http://info.template-help.com/files/ie6_warning/ie6_script_other.js"></script>
<script type="text/javascript" src="js/html5.js"></script>
<![endif]-->
<?php $error_messages = array(
'T1' => 'Please enter a Name to proceed.',
'T2' => 'Please enter a valid Email Address to continue.',
'T3' => 'Please enter your Message to continue.'
);
?>
</head>
<body id="page2">
<div class="body1">
<div class="main">
<!-- header -->
<header>
<div class="wrapper">
<h1>Air Lines<span id="slogan">International Travel</span></h1>
<div class="right">
<nav>
<ul id="top_nav">
<li><img src="images/img1.gif" alt=""></li>
<li><img src="images/img2.gif" alt=""></li>
<li class="bg_none"><img src="images/img3.gif" alt=""></li>
</ul>
</nav>
<nav>
<ul id="menu">
<li>Home</li>
<li id="menu_active" >Login/sign up</li>
<li>Vision and mission</li>
<li>Contacts</li>
</ul>
</nav>
</div>
</div>
</header>
</div>
</div>
<div class="main">
<div id="banner"></div>
</div>
<!-- header -->
<div class="main">
<!-- content -->
<section id="content">
<article class="col1">
<div class="pad_1">
<h2>Login</h2>
<form id="form_1" action="login.php" method="post">
<div class="wrapper">
User Name:
<div class="bg"><input type="text" name="LogIn_Name" class="input input1" value="Enter your name" onblur="if(this.value=='') this.value='Enter your name'" onfocus="if(this.value =='Enter your name' ) this.value=''"></div>
</div>
<div class="wrapper">
Password:
<div class="bg"><input type="password" name="LogIn_Pass" class="input input1" value="Enter your password" onblur="if(this.value=='') this.value='Enter your password'" onfocus="if(this.value =='Enter your password' ) this.value=''"></div>
</div>
<div class="wrapper">
<h2 id="coq"> Forget Password</h2>
<input type="submit" class="button2" value="GO">
</div>
</form>
<h2> </h2>
</div>
</article>
<article class="col2 pad_left1">
<h2>Registration</h2>
<div class="wrapper">
<figure class="left marg_right1"></figure>
<p>
<form id="form_1" action="" method="post">
<div class="wrapperr" >
<?php
$username = $_POST["T1"];
$password = $_POST["T2"];
$repassword = $_POST["T3"];
$email = $_POST["T4"];
$gender = $_POST["T5"];
$Cou = $_POST["T6"];
$DO= $_POST["T7"];
$passport= $_POST["T8"];
$phone= $_POST["T9"];
{
if((strlen($username)<3)){
echo "The username is too short"."</br>";
if((strlen($gender)<3)){
echo "Gender"."</br>";
}
if((strlen($Cou)<2)){
echo "The CO too short"."</br>";
}
if((strlen($phone)<5)){
echo "The phone is too short"."</br>";
}
if((strlen($password)<5)){
echo "The password is too short"."</br>";
}
}
else{
if($password == $repassword){
$chec = mysql_query("SELECT * FROM register WHERE name='$username'");
if(strlen($chec['name'])>0){
echo "The username '$username' already exists";
}
else{
$check_variable=stripos($email,"#");
if($check_variable){
$password=md5($password);
mysql_query("INSERT INTO register (name,password,email,gender,country,DOB,phone,passport) VALUES ('$username','$password','$email','$gender','$Cou','$DO','$phone','$passport')");
echo "Registration Successful .. Click <a href='index.php'> here </a> to home";
}
else{
echo "email is invalid";
}
}
}
else{
echo "The password in both field doesn't match.";
}
}
}
?>
</div> <div class="wrapper">
Name:
<div class="bg"><input type="text" name="T1" class="input input1" value="Enter your name" onblur="if(this.value=='') this.value='Enter your name'" onfocus="if(this.value =='Enter your name' ) this.value=''"></div>
</div>
<div class="wrapper">
Password:
<div class="bg"><input type="password" name="T2" class="input input1" value="Enter the password" onblur="if(this.value=='') this.value='Enter the password'" onfocus="if(this.value =='Enter the password' ) this.value=''"></div>
</div>
<div class="wrapper">
Confirm password:
<div class="bg"><input type="password" name="T3" class="input input1" value="Confirm the password" onblur="if(this.value=='') this.value='Confirm the password'" onfocus="if(this.value =='Confirm the password' ) this.value=''"></div>
</div>
<div class="wrapper">
e-mail:
<div class="bg"><input type="text" name = "T4" class="input input1" value="Enter your e-mail" onblur="if(this.value=='') this.value='Enter your e-mail'" onfocus="if(this.value =='Enter your e-mail' ) this.value=''"></div>
</div>
<div class="wrapper">
Gender:
<div class="bg">
<td>
<input type="radio" name="T5" value="Male">
Male
</td><td>
<input type="radio" name="T5" value="Female">
Female</td>
</div>
</div>
<div class="wrapper">
NATIONALITY:
<div class="bg"><input type="text" name="T6" class="input input1" value="Enter your country" onblur="if(this.value=='') this.value='Enter your country'" onfocus="if(this.value =='Enter your country' ) this.value=''"></div>
</div>
<div class="wrapper">
<div class="wrapper">
Passport number:
<div class="bg"><input type="text" name="T8" class="input input1" value="Enter your passport number" onblur="if(this.value=='') this.value='Enter your passport number'" onfocus="if(this.value =='Enter your passport number' ) this.value=''"></div>
</div>
<div class="wrapper">
Date of birth:
<div class="wrapper">
<div class="bg left"><input type="text" name="T7" class="input input2" value="mm/dd/yyyy " onblur="if(this.value=='') this.value='mm/dd/yyyy '" onfocus="if(this.value =='mm/dd/yyyy ' ) this.value=''" id="datepicker" >
<br/><span id="bdayInfo"></span>
</div>
<div class="bg right"></div>
</div>
</div>
Phone number:
<div class="wrapper">
<div class="bg left"><input type="text" name="T9" class="input input2" value="" onblur="if(this.value=='') this.value=''" onfocus="if(this.value =='' ) this.value=''"></div>
<div class="bg right"></div>
</div>
</div>
<div class="wrapper">
<p> </p>
<input type="submit" class="button2" name="Go" value="GO">
</div>
</form>
</p>
</div>
<p> </p>
<h2> </h2>
</article>
</section>
<!-- / content -->
</div>
<div class="body2">
<div class="main">
<!--footer -->
<footer>
Website template designed by www.templatemonster.com<br>
3D Models provided by www.templates.com
</footer>
<!-- / footer -->
</div>
</div>
<script type="text/javascript"> Cufon.now(); </script>
</body>
</html>
Always validate server side first i.e. in PHP (this is the point where it is required).
Then add JavaScript validation afterwards. It is not required, but added to improve user expecrience. Any javascript can be circumnavigated (avoided) so if you don't have the PHP backup then you're leaving your self open for trouble.
Note, I'm not saying don't add JS validation, merely that you add PHP first, JS second. Sometimes you find libraries / frameworks that can add both at the same time.
So back to your code: the error appears to be that you're checking for errors after you display the error. So it's going to fail.
Restructure your code as follows:
Create default values for your form
Create blank errors array.
If POSTED, then read in values (over defaults), validate them
If all is good, then process the form and redirect [header('location: '); exit();] to a results / thank-you page.
(Note that at this point you have not outputted any HTML at all, merely updated your default values and error array)
If all is not good (or you never got a post) then now show the HTML. You have default values for the inputs (will alos contain the POSTED values, if applicable) and error messages to display at the right points.
Basically, handle the data first, output last.
Once that is working, then ass jQuery validation (as suggested in comments). It's pretty good.
HTML 5 has a bunch of built in validation tools and you could use jQuery or Javascript to further enhance that. I am not a big fan of validating variables on a new page, especially when we could prevent the page load completely. Definitely look into some sort of Client Side validation instead of posting to the the PHP page.
W3Schools has a decent article on Javascript validation: http://www.w3schools.com/js/js_form_validation.asp
The jQuery link was already given in a comment above.
If Javascript is not your specialty then try something like this. It is prebuilt and has some nice features. Best of all it is free.
http://www.javascript-coder.com/html-form/javascript-form-validation.phtml