I tried to make a login page on WHMCS with PHP. My code is like:
<div class="clearfix"></div>
<div class="header_medium two">
<div class="container">
<h3 class="bigtext"> We are <span>Foxuhost.</span></h3>
<h3 class="smalltext"><span>Get 7+</span> Unique Layouts</h3>
</div>
</div>
<!--end header medium-->
<div class="section_holder18">
<div class="container">
<div class="pagetitle">
<h3>Login form</h3>
</div>
<div class="pagenation"> Home <i>/</i> Pages <i>/</i> Login form</div>
</div>
</div>
<!--end pagenation-->
<div class="clearfix"></div>
<div class="section_holder27" name="l1">
<div class="container" name="l2">
<div class="login_form" name="l3">
<form method="post" id="sky-form" class="sky-form" name="l4">
<header>Login form</header>
<fieldset name="l5">
<section name="l6">
<div class="row" name="l7">
<label class="label col col-4">E-mail</label>
<div class="col col-8"name="l8">
<label class="input" name="l9">
<i class="icon-append icon-user"></i>
<input type="email" name="emailer">
</label>
</div>
</div>
</section>
<section>
<div class="row">
<label class="label col col-4">Password</label>
<div class="col col-8">
<label class="input">
<i class="icon-append icon-lock"></i>
<input type="password" name="password6">
</label>
<div class="note">Forgot password?</div>
</div>
</div>
</section>
<section>
<div class="row">
<div class="col col-4"></div>
<div class="col col-8">
<label class="checkbox"><input type="checkbox" name="remember" checked><i></i>Keep me logged in</label>
</div>
</div>
</section>
</fieldset>
<footer>
<div class="fright">
Register
<button type="submit" name="send" value="send" class="button eight">Log in</button>
</div>
</footer>
</form>
</div>
<form action="http://trixia.dk/templates/d/demo-recovery.php" id="sky-form2" class="sky-form sky-form-modal">
<header>Password recovery</header>
<fieldset>
<section>
<label class="label">E-mail</label>
<label class="input">
<i class="icon-append icon-user"></i>
<input type="email" name="email" id="email">
</label>
</section>
</fieldset>
<footer>
<button type="submit" name="submit" class="button">Submit</button>
Close
</footer>
<div class="message">
<i class="icon-ok"></i>
<p>Your request successfully sent!<br>Close window</p>
</div>
</form>
{if $_post["emailer"] != ""}
<div class="error-box alert"> <span><i class="fa fa-exclamation-triangle"></i> Error – message will goes here</span> <a class="mboxes_close" href="#"><i class="fa fa-times"></i></a> </div><!--end item-->
{else}
<h1>asdasd</h1>
{/if}
</div>
</div>
<!--end section 22-->
{literal}
<script type="text/javascript">
function validerform125() {
var email = document.getElementsByName("password6")[0].value;
var password = document.getElementsByName("emailer")[0].value;
if (email == "" && password == "") {
alert("Du skal udfylde alle felter");
}
else if (email == "") {
alert("Du har ikke skrevet noget email");
return false;
}else if (password == "") {
alert("Du har ikke skrevet noget password");
return false;
}else if(email != $values["email"]) {
alert("Dit brugernavn er ikke rigtigt");
return false;
}else if() {
}
else{
alert("Der skete noget");
return false;
}
}
</script>
{/literal}
the if statements is a bit over <!--end section 22-->
I tried it on a smaller website and it works fine.
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post">
<div>
Navn <input name="navn" type="text"><br/>
Email <input name="email" type="email"><br/>
</div>
<div>
<input type="submit" name="send" value="send">
</div>
</form>
<?php
if ($_POST["navn"] == "") {
echo "hejsa";
return;
}else{
echo "hejsa2";
}
?>
</body>
</html>
The error is that when i press the login button it doesn't do the if statement. But it prints out the "else" statement, when i load the website.
Is the first file you provided a smarty .tpl file? If so, you will need to change the bottom section to something like this:
...
</div>
</form>
{php}if ( $_POST["emailer"] != "" ) :{/php}
<div class="error-box alert"> <span><i class="fa fa-exclamation-triangle"></i> Error – message will goes here</span> <a class="mboxes_close" href="#"><i class="fa fa-times"></i></a> </div><!--end item-->
{php}else:{/php}
<h1>asdasd</h1>
{php}endif;{/php}
</div>
</div>
...
Smarty doesn't know you need to execute PHP unless you tell it. This is also assuming you are not running version 6 of WHMCS with the new execute PHP option disabled in the settings (v6 is still beta as of May 2015 however).
Hope that helps.
Related
Im using the COMMMENT FORM in WORDPRESS but I wanna customize the form.The form is wraped by default:
<div id="respond" class="comment-respond">
...
</div>
Now I want to add some class attributes to tag.So can I use filter hook to make that or anyone have good idea for this problem.Thanks
This is code of file comments.php:
<div class="wilpost-component__module mb-30">
<?php if (have_comments() == false) { ?>
<h3 class="postComponent-title">No comment</h3>
<?php } else { ?>
<h3 class="postComponent-title"><?php echo esc_html("(" . get_comments_number() . ")comment"); ?></h3>
<div class="wilpost-comment__module">
<ol class="commentlist">
<?php
wp_list_comments(array('callback' => 'fractal_comment', "style" => "ol"));
?>
</ol>
</div>
<?php } ?>
</div>
<?php comment_form();?>
And this is code I wanna customize my comment form like this:
<div class="wilform__module wilform__feedback">
<form name="wil-feedback" id="wil-feedback" action="#">
<div class="item-group">
<label for="name">name</label>
<input type="text" id="name"/>
<div class="form-icon"><i class="fa fa-user"></i></div>
</div>
<div class="item-group">
<label for="email">email</label>
<input type="email" id="email"/>
<div class="form-icon"><i class="fa fa-envelope"></i></div>
</div>
<div class="item-group">
<label for="textarea">textarea</label>
<textarea></textarea>
</div>
<button class="wil-btn wil-btn--primary wil-btn--md wil-btn--round " type="submit">Subscrible<i class="la la-paper-plane"></i>
</button>
</form>
</div>
I am currently using a PHP script to add a record into my database, this works properly after some debugging. When the script runs, it opens a new page with the query output.
I'd like to display the query output on the same page that executes the query, at the top of the page, under my navbar.
Below is my current page.
This is the desired result.
The relevant code of the HTML page:
<form name="registration" action="addKlant.php" target="_blank" method="post">
<h3><i class="fa fa-plus-circle"></i> Klant toevoegen</h3>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Naam</label>
<input type="text" name="klantNaam">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Soort klant</label>
<select class="" name="klantSoort">
<option value="">Bedrijf</option>
<option value="">Particulier</option>
</select>
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Telefoonnummer</label>
<input type="number" name="klantTel">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> E-mail adres</label>
<input type="email" name="klantEmail">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Straat & huisnr</label>
<input type="text" name="klantAdres">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Postcode</label>
<input type="text" name="klantPostcode">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Plaats</label>
<input type="text" name="klantPlaats">
</div>
<div class="form-input">
<input type="submit" name="submit" value="Klant toevoegen">
</div>
</form>
addKlant.php
<?php
require('db.php');
$stmt = $con->prepare('INSERT INTO `klanten` (klant_naam, klant_soort, klant_telefoon, klant_email, klant_straat, klant_postcode, klant_plaats) VALUES (?, ?, ?, ?, ?, ?, ?)');
if($stmt) {
$klant_naam = $_POST['klantNaam'];
$klant_soort = $_POST['klantSoort'];
$klant_telefoon = $_POST['klantTel'];
$klant_email = $_POST['klantEmail'];
$klant_adres = $_POST['klantAdres'];
$klant_postcode = $_POST['klantPostcode'];
$klant_plaats = $_POST['klantPlaats'];
$stmt->bind_param('ssissss', $klant_naam, $klant_soort, $klant_telefoon, $klant_email, $klant_adres, $klant_postcode, $klant_plaats);
$stmt->execute();
$con->close();
echo "Klant is toegevoegd, je kan deze pagina nu sluiten.";
}
?>
I was thinking about using something like if($_POST)? But I do not know how to implement it exactly.
It does not matter if the page refreshes to add the output, but I would like to keep it to PHP and not use JS (of course, if it is possible with only PHP).
Any tips are greatly appreciated.
EDIT: Edited my code with some help from #SloanTrasher
<?php
if($_POST['submit'] == 'Klant toevoegen') {
require('db.php');
$stmt = $con->prepare('INSERT INTO `klanten` (klant_naam, klant_soort, klant_telefoon, klant_email, klant_straat, klant_postcode, klant_plaats) VALUES (?, ?, ?, ?, ?, ?, ?)');
if($stmt) {
$klant_naam = $_POST['klantNaam'];
$klant_soort = $_POST['klantSoort'];
$klant_telefoon = $_POST['klantTel'];
$klant_email = $_POST['klantEmail'];
$klant_adres = $_POST['klantAdres'];
$klant_postcode = $_POST['klantPostcode'];
$klant_plaats = $_POST['klantPlaats'];
$stmt->bind_param('ssissss', $klant_naam, $klant_soort, $klant_telefoon, $klant_email, $klant_adres, $klant_postcode, $klant_plaats);
$stmt->execute();
$con->close();
}
}
?>
<!-- I placed it above the form for simplification -->
<?php ($_POST['submit'] == 'Klant toevoegen') {echo "<p>Klant is toegevoegd.</p>";}?>
<form name="registration" action="addKlant.php" target="_blank" method="post">
<h3><i class="fa fa-plus-circle"></i> Klant toevoegen</h3>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Naam</label>
<input type="text" name="klantNaam">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Soort klant</label>
<select class="" name="klantSoort">
<option value="">Bedrijf</option>
<option value="">Particulier</option>
</select>
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Telefoonnummer</label>
<input type="number" name="klantTel">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> E-mail adres</label>
<input type="email" name="klantEmail">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Straat & huisnr</label>
<input type="text" name="klantAdres">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Postcode</label>
<input type="text" name="klantPostcode">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Plaats</label>
<input type="text" name="klantPlaats">
</div>
<div class="form-input">
<input type="submit" name="submit" value="Klant toevoegen">
</div>
</form>
EDIT 2: Working code for anyone interested
<?php
include('auth.php');
if($_POST['submit'] == 'Klant toevoegen') {
require('db.php');
$stmt = $con->prepare('INSERT INTO `klanten` (klant_naam, klant_soort, klant_telefoon, klant_email, klant_straat, klant_postcode, klant_plaats) VALUES (?, ?, ?, ?, ?, ?, ?)');
if($stmt) {
$klant_naam = $_POST['klantNaam'];
$klant_soort = $_POST['klantSoort'];
$klant_telefoon = $_POST['klantTel'];
$klant_email = $_POST['klantEmail'];
$klant_adres = $_POST['klantAdres'];
$klant_postcode = $_POST['klantPostcode'];
$klant_plaats = $_POST['klantPlaats'];
$stmt->bind_param('ssissss', $klant_naam, $klant_soort, $klant_telefoon, $klant_email, $klant_adres, $klant_postcode, $klant_plaats);
$stmt->execute();
$con->close();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Charset, viewport en keywords -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Titel en favicon -->
<title></title>
<link rel="icon" href="./img/favicon.jpg">
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="./js/pageForward.js"></script>
<script type="text/javascript" src="./js/pageBack.js"></script>
<!-- Stylesheets en fonts -->
<link rel="stylesheet" href="./css/backend_styles.css">
<link href="https://fonts.googleapis.com/css?family=Work+Sans:200" rel="stylesheet"> <!-- font-family: 'Work Sans', sans-serif; -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"> <!-- font-family: 'Open Sans', sans-serif; -->
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="top-links">
<p><i class="fa fa-home"></i><i class="fa fa-cogs"></i><a onclick="goBack()"><i class="fa fa-arrow-left"></i></a><a onclick="goForward()"><i class="fa fa-arrow-right"></i></a> Backoffice | Ingelogt als: <?php echo $_SESSION['username']; ?> | Uitloggen</p>
</div>
<?php if($_POST['submit'] == 'Klant toevoegen') {echo "<p>Klant is toegevoegd.</p>";}?>
<div class="inner-container">
<div class="backend-form">
<form name="registration" method="post">
<h3><i class="fa fa-plus-circle"></i> Klant toevoegen</h3>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Naam</label>
<input type="text" name="klantNaam">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Soort klant</label>
<select class="" name="klantSoort">
<option value="Bedrijf">Bedrijf</option>
<option value="Particulier">Particulier</option>
</select>
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Telefoonnummer</label>
<input type="number" name="klantTel">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> E-mail adres</label>
<input type="email" name="klantEmail">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Straat & huisnr</label>
<input type="text" name="klantAdres">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Postcode</label>
<input type="text" name="klantPostcode">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Plaats</label>
<input type="text" name="klantPlaats">
</div>
<div class="form-input">
<input type="submit" name="submit" value="Klant toevoegen">
</div>
</form>
</div>
</div>
</div>
<footer>
<p>Copyright © 2018</p>
</footer>
</body>
</html>
Here's the working code. Glad you got it working!
<?php
include('auth.php');
if($_POST['submit'] == 'Klant toevoegen') {
require('db.php');
$stmt = $con->prepare('INSERT INTO `klanten` (klant_naam, klant_soort, klant_telefoon, klant_email, klant_straat, klant_postcode, klant_plaats) VALUES (?, ?, ?, ?, ?, ?, ?)');
if($stmt) {
$klant_naam = $_POST['klantNaam'];
$klant_soort = $_POST['klantSoort'];
$klant_telefoon = $_POST['klantTel'];
$klant_email = $_POST['klantEmail'];
$klant_adres = $_POST['klantAdres'];
$klant_postcode = $_POST['klantPostcode'];
$klant_plaats = $_POST['klantPlaats'];
$stmt->bind_param('ssissss', $klant_naam, $klant_soort, $klant_telefoon, $klant_email, $klant_adres, $klant_postcode, $klant_plaats);
$stmt->execute();
$con->close();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Charset, viewport en keywords -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Titel en favicon -->
<title></title>
<link rel="icon" href="./img/favicon.jpg">
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="./js/pageForward.js"></script>
<script type="text/javascript" src="./js/pageBack.js"></script>
<!-- Stylesheets en fonts -->
<link rel="stylesheet" href="./css/backend_styles.css">
<link href="https://fonts.googleapis.com/css?family=Work+Sans:200" rel="stylesheet"> <!-- font-family: 'Work Sans', sans-serif; -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"> <!-- font-family: 'Open Sans', sans-serif; -->
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="top-links">
<p><i class="fa fa-home"></i><i class="fa fa-cogs"></i><a onclick="goBack()"><i class="fa fa-arrow-left"></i></a><a onclick="goForward()"><i class="fa fa-arrow-right"></i></a> Backoffice | Ingelogt als: <?php echo $_SESSION['username']; ?> | Uitloggen</p>
</div>
<?php if($_POST['submit'] == 'Klant toevoegen') {echo "<p>Klant is toegevoegd.</p>";}?>
<div class="inner-container">
<div class="backend-form">
<form name="registration" method="post">
<h3><i class="fa fa-plus-circle"></i> Klant toevoegen</h3>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Naam</label>
<input type="text" name="klantNaam">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Soort klant</label>
<select class="" name="klantSoort">
<option value="Bedrijf">Bedrijf</option>
<option value="Particulier">Particulier</option>
</select>
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Telefoonnummer</label>
<input type="number" name="klantTel">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> E-mail adres</label>
<input type="email" name="klantEmail">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Straat & huisnr</label>
<input type="text" name="klantAdres">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Postcode</label>
<input type="text" name="klantPostcode">
</div>
<div class="form-input">
<label><i class="fa fa-info-circle"></i> Plaats</label>
<input type="text" name="klantPlaats">
</div>
<div class="form-input">
<input type="submit" name="submit" value="Klant toevoegen">
</div>
</form>
</div>
</div>
</div>
<footer>
<p>Copyright © 2018</p>
</footer>
</body>
</html>
I'm assuming that the HTML form is not part of addKlant.php?
In which case, once you've processed the form, you might want to redirect to the page with the HTML form, and pass an item in the querystring with some sort of variable to show the query has run.
i.e.
// ... after your form processing
$con->close();
header("Location: htmlpage.php?queryresult=ok");
exit;
and then in the HTML form page:
<?php if ($_GET['queryresult'] == 'ok') print "query ran okay"; ?>
I don't know what the result of the query might look like - if it is encodable within a url, you can pass this whole response, ie.
header("Location: htmlpage.php?queryresult=" . urlencode( $queryresultstring ));
Here is my index page where i can successfully login but wont redirect to any page? just new been trying to get it to working.
<?php include('header.php'); ?>
<body>
<div class="container">
<div style="height:50px;">
</div>
<div class="row" id="loginform">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><span class="glyphicon glyphicon-lock"></span> Login
<span class="pull-right"><span class="glyphicon glyphicon-pencil"></span> <a style="text-decoration:none; cursor:pointer; color:white;" id="signup">Sign up</a></span>
</h3>
</div>
<!-- Body For Login -->
<div class="panel-body">
<form role="form" id="logform">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Username" name="username" id="username" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" id="password" type="password">
</div>
<button type="button" id="loginbutton" class="btn btn-lg btn-primary btn-block"><span class="glyphicon glyphicon-log-in"></span> <span id="logtext">Login</span></button>
</fieldset>
</form>
<!-- Body For Login -->
</div>
</div>
</div>
</div>
<div class="row" id="signupform" style="display:none;">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><span class="glyphicon glyphicon-pencil"></span> Sign Up
<span class="pull-right"><span class="glyphicon glyphicon-log-in"></span> <a style="text-decoration:none; cursor:pointer; color:white;" id="login">Login</a></span>
</h3>
</div>
<div class="panel-body">
<!-- Body for Sign up -->
<form role="form" id="signform">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Full Name" name="name" id="name" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Email" name="email" id="email" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Username" name="susername" id="susername" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="spassword" id="spassword" type="password">
</div>
<button type="button" id="signupbutton" class="btn btn-lg btn-primary btn-block"><span class="glyphicon glyphicon-check"></span> <span id="signtext">Sign Up</span></button>
</fieldset>
</form>
<!-- Body for Sign up -->
</div>
</div>
</div>
</div>
<div id="myalert" style="display:none;">
<div class="col-md-4 col-md-offset-4">
<div class="alert alert-info">
<center><span id="alerttext"></span></center>
</div>
</div>
</div>
</div>
<script src="custom.js"></script>
</body>
</html>
i don't know why but just keep going back to index.page
<?php
include('conn.php');
session_start();
if(isset($_POST['logform'])){
$username=$_POST['username'];
$password=md5($_POST['password']);
$query=$conn->query("select * from users where username='$username' and password='$password'");
if ($query->num_rows>0) {
$row=$query->fetch_array();
if ($row['level']=="admin") {
$_SESSION['users']=$row['id'];
$_SESSION['level']=$row['level'];
header('location: admin/index.php');
}elseif ($row['level']=="agent") {
$_SESSION['users']=$row['id'];
$_SESSION['level']=$row['level'];
header('location: agent/index.php');
}elseif ($row['level']=="user") {
$_SESSION['users']=$row['id'];
$_SESSION['level']=$row['level'];
header('location: agent/index.php');
}else{
?>
<span>Login Failed. User not Found.</span>
<?php
}
}
}
Here is my login action form it working but will not redirect to any page that i set them i don't know why but im trying my best how to work around the problem
Here is my custom.js which tell the php what to do next
$(document).ready(function(){
//bind enter key to click button
$(document).keypress(function(e){
if (e.which == 13){
if($('#loginform').is(":visible")){
$("#loginbutton").click();
}
else if($('#signupform').is(":visible")){
$("#signupbutton").click();
}
}
});
$('#signup').click(function(){
$('#loginform').slideUp();
$('#signupform').slideDown();
$('#myalert').slideUp();
$('#signform')[0].reset();
});
$('#login').click(function(){
$('#loginform').slideDown();
$('#signupform').slideUp();
$('#myalert').slideUp();
$('#logform')[0].reset();
});
$(document).on('click', '#signupbutton', function(){
if($('#susername').val()!='' && $('#spassword').val()!=''){
$('#signtext').text('Signing up...');
$('#myalert').slideUp();
var signform = $('#signform').serialize();
$.ajax({
method: 'POST',
url: 'signup.php',
data: signform,
success:function(data){
setTimeout(function(){
$('#myalert').slideDown();
$('#alerttext').html(data);
$('#signtext').text('Sign up');
$('#signform')[0].reset();
}, 2000);
}
});
}
else{
alert('Please input both fields to Sign Up');
}
});
$(document).on('click', '#loginbutton', function(){
if($('#username').val()!='' && $('#password').val()!=''){
$('#logtext').text('Logging in...');
$('#myalert').slideUp();
var logform = $('#logform').serialize();
setTimeout(function(){
$.ajax({
method: 'POST',
url: 'login.php',
data: logform,
success:function(data){
if(data==''){
$('#myalert').slideDown();
$('#alerttext').text('Login Successful. User Verified!');
$('#logtext').text('Login');
$('#logform')[0].reset();
setTimeout(function(){
location.reload();
}, 2000);
}
else{
$('#myalert').slideDown();
$('#alerttext').html(data);
$('#logtext').text('Login');
$('#logform')[0].reset();
}
}
});
}, 2000);
}
else{
alert('Please input both fields to Login');
}
});
});
Try to use
<input type ="submit" id="loginbutton">
instead of
<button type="button" id="loginbutton">
to post your form.
Change
header('location: admin/index.php');
to
header('Location: agent/index.php');
it is an easy mistake to make
You forgot to define the methodand action in form tag. The method attribute specifies how to send form-data. When posting a form, it always good to have a method is post. As for action, a route or file location where action should perform.
So try this:
<form method="post" action="/{_action_filename_}.php">
I have two form in one page. When I click on the submit button of form one, the validation error shows on both forms. How could show separate validation errors on each form?
This is my view:
<?php echo form_open('user_signup/login',['class'=>'login-form','id'=>'submit_form']);
echo validation_errors();?>
<h3 class="form-title font-green">Sign In</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span> Enter any username and password. </span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email1','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email1')]); ?>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<?php echo form_input(['name'=>'pass','type'=>'password','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Password']); ?>
</div>
<div class="form-actions">
<?php echo form_submit('submit', 'Submit',"class='btn green uppercase'" ); ?>
Forgot Password?
</div>
<div class="login-options">
<h4>Or login with</h4>
<ul class="social-icons">
<li>
<a class="social-icon-color facebook" data-original-title="facebook" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color twitter" data-original-title="Twitter" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color googleplus" data-original-title="Goole Plus" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color linkedin" data-original-title="Linkedin" href="javascript:;"></a>
</li>
</ul>
</div>
<div class="create-account">
<p>
Create an account
</p>
</div>
</form>
<!-- END LOGIN FORM -->
<!-- BEGIN FORGOT PASSWORD FORM -->
<form class="forget-form" action="http://keenthemes.com/preview/metronic/theme/admin_2/index.html" method="post">
<h3 class="font-green">Forget Password ?</h3>
<p> Enter your e-mail address below to reset your password. </p>
<div class="form-group">
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Email" name="email" /> </div>
<div class="form-actions">
<button type="button" id="back-btn" class="btn green btn-outline">Back</button>
<button type="submit" class="btn btn-success uppercase pull-right">Submit</button>
</div>
</form>
<!-- END FORGOT PASSWORD FORM -->
<!-- BEGIN REGISTRATION FORM -->
<?php echo form_open('user_signup/login',['class'=>'register-form','id'=>'register_form']);
?>
<h3 class="font-green">Sign Up</h3>
<p class="hint"> Enter your personal details below: </p>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Roll NO</label>
<?php echo form_input(['name'=>'rollno','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Rollno','value'=>set_value('rollno')]); ?>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email2','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email2')]); ?>
</div>
<div class="form-actions">
<button type="button" id="register-back-btn" class="btn green btn-outline">Back</button>
<?php echo form_submit('register', 'register',"class='btn btn-success uppercase pull-right'" ); ?>
This is my controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_signup extends CI_Controller {
public function index()
{
$this->load->view('User/signup');
}
public function login()
{
if ($this->input->post('submit_form')) {
$rules['email1'] = 'required';
$rules['pass'] = 'required';
$this->form_validation->set_rules($rules);
}
else if ($this->input->post('register_form')) {
$rules['rollno'] = 'required';
$rules['email2'] = 'required';
$this->validation->set_rules($rules);
}
if (!$this->form_validation->run()) {
$this->load->view('User/signup');
}
else {
if ($this->input->post('submit_form'))
echo 'Form 1 posted !';
else if ($this->input->post('register_form'))
echo 'Form 2 posted !';
}
}
}
There are two things you need to concern about that. First passing action in HTML form. Second is, getting those parameters and code accordingly in your controller's action.
<?php echo form_open('user_signup/login/form-1',['class'=>'login-form','id'=>'submit_form']);
echo validation_errors();?>
<h3 class="form-title font-green">Sign In</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span> Enter any username and password. </span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email1','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email1')]); ?>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<?php echo form_input(['name'=>'pass','type'=>'password','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Password']); ?>
</div>
<div class="form-actions">
<?php echo form_submit('submit', 'Submit',"class='btn green uppercase'" ); ?>
Forgot Password?
</div>
<div class="login-options">
<h4>Or login with</h4>
<ul class="social-icons">
<li>
<a class="social-icon-color facebook" data-original-title="facebook" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color twitter" data-original-title="Twitter" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color googleplus" data-original-title="Goole Plus" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color linkedin" data-original-title="Linkedin" href="javascript:;"></a>
</li>
</ul>
</div>
<div class="create-account">
<p>
Create an account
</p>
</div>
</form>
<!-- END LOGIN FORM -->
<!-- BEGIN FORGOT PASSWORD FORM -->
<form class="forget-form" action="http://keenthemes.com/preview/metronic/theme/admin_2/index.html" method="post">
<h3 class="font-green">Forget Password ?</h3>
<p> Enter your e-mail address below to reset your password. </p>
<div class="form-group">
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Email" name="email" /> </div>
<div class="form-actions">
<button type="button" id="back-btn" class="btn green btn-outline">Back</button>
<button type="submit" class="btn btn-success uppercase pull-right">Submit</button>
</div>
</form>
<!-- END FORGOT PASSWORD FORM -->
<!-- BEGIN REGISTRATION FORM -->
<?php echo form_open('user_signup/login/form-2',['class'=>'register-form','id'=>'register_form']);
?>
<h3 class="font-green">Sign Up</h3>
<p class="hint"> Enter your personal details below: </p>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Roll NO</label>
<?php echo form_input(['name'=>'rollno','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Rollno','value'=>set_value('rollno')]); ?>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email2','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email2')]); ?>
</div>
<div class="form-actions">
<button type="button" id="register-back-btn" class="btn green btn-outline">Back</button>
<?php echo form_submit('register', 'register',"class='btn btn-success uppercase pull-right'" ); ?>
Note: Check form actions
Here is your updated controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_signup extends CI_Controller {
public function index()
{
$this->load->view('User/signup');
}
public function login()
{
// Checking passed 3rd parameter in URI string.
$submitted_form = $this->uri->segment(3)?$this->uri->segment(3):false;
if ($submitted_form == 'form-1') {
$rules['email1'] = 'required';
$rules['pass'] = 'required';
$this->form_validation->set_rules($rules);
}
if ($submitted_form == 'form-2') {
$rules['rollno'] = 'required';
$rules['email2'] = 'required';
$this->validation->set_rules($rules);
}
if ($this->form_validation->run()) {
if ($submitted_form == 'form-1')
echo 'Form 1 posted !';
else if ($submitted_form == 'form-1')
echo 'Form 2 posted !';
}
$this->load->view('User/signup');
}
}
Let me know if you have any confusion.
Submit by Jquery. For Example in your view
<form id="form1" action="" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<input type="hidden" name="form_type" value="login">
<button type="submit" onClick="login()">Login</button>
</form>
<form id="form2" action="" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<label>Email</label>
<input type="email" name="email">
<input type="hidden" name="form_type" value="register">
<button type="submit" onClick="register()">Login</button>
</form>
Jquery Script
<script>
function login()
{
$('#form1').submit();
}
function register()
{
$('#form2').submit();
}
</script>
Now in your controller
if($_POST)
{
if($_POST['form_type']=='login')
{
// Validate Login
}
elseif($_POST['form_type']=='register')
{
// validate register
}
}
there are two forms one is registration form and another is sign in form .When am registring with registration form its div element is fetching message from php using isset funtion but when i am doing same thing with sign in it is redirecting page to homepage please help what can i do if am trying to match database if not matched it will fetch value from php and show in the div as in the code
<?php
if (!empty($_POST['finish'])) {
//do something here;
include'php/signup.php';
}
if (!empty($_POST['go'])) {
include'php/signin.php';
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/homepage.css">
<link rel="stylesheet" type="text/css" href="css/login.css">
<link rel="stylesheet" type="text/css" href="css/signup.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/login.js"></script>
<script src="js/signup.js"></script>
<script>
function hideMessage() {
document.getElementById("message").style.display = "none";
};
setTimeout(hideMessage, 5000);
</script>
</head>
<body >
<!--row starts here -->
<div class="row">
<div class="col-1-2">
</div>
<div class="col-1-2">
<div class="container">
<ul class="tabs">
<li class="tab-link current" data-tab="tab-1">Sign Up</li>
<li class="tab-link" data-tab="tab-2">Sign In</li>
</ul>
<div id="tab-1" class="tab-content current">
<div id="message"><?php if(isset($message)) echo $message; ?></div>
<ul id="registration-step">
<li id="account" class="highlight">Account</li>
<li id="password">Password</li>
<li id="general">Nick Name</li>
</ul>
<form name="frmRegistration" id="registration-form" method="post">
<div id="account-field">
<span id="email-error" class="registration-error"></span>
<div><input type="text" name="email" id="email" class="demoInputBox" placeholder="E-mail"/></div>
</div>
<div id="password-field" style="display:none;">
<span id="password-error" class="registration-error"></span>
<div><input type="password" name="password" id="user-password" class="demoInputBox" placeholder="Password"required /></div>
</div>
<div id="general-field" style="display:none;">
<div><input type="text" name="nickname" id="display-name" class="demoInputBox" placeholder="Nick Name"/></div>
</div>
<div>
<input class="btnAction" type="button" name="back" id="back" value="Back" style="display:none;">
<input class="btnAction" type="button" name="next" id="next" value="Next" >
<input class="btnAction" type="submit" name="finish" id="finish" value="Finish" style="display:none;">
</div>
</form>
</div>
<div id="tab-2" class="tab-content">
<div id="signinmsg"><?php if(isset($msg1)) echo $msg1; ?></div>
<form name="signin"method="post">
<input type="text" name="signinemail"class="demoInputBox"placeholder="E-mail">
<br><br>
<input type="text" class="demoInputBox"name="signinpass"placeholder="Password"><br><br>
<input class="btnAction" type="submit" name="go" id="go" value="Go.." >
</form>
</div>
</div>
</div>
<!--this row ends here -->
</body>
</html>
You should be checking if isset and not !empty
<?php
if (isset($_POST['finish'])) {
//do something here;
include'php/signup.php';
}
if (isset($_POST['go'])) {
include'php/signin.php';
}
?>