Button implements the wrong code when press 'enter' button - php

I am writing code that is meant to log in users.
The login and search worked before but, ever since I combined the two the login form doesn't implement it's own code and instead, it runs the search code
EDIT: I found out why this happens, it's because I have been pressing enter instead of selecting login. So now I want to know, how do I press enter and implement the login code.
Below is the headerPublic.php which contains the search code
<?php
//---------------------BEGIN SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
if(isset($_POST["search_button"]))
{
//PHP SEARCH CODE
}
//---------------------END SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
?>
<html>
<head>
<title>VCR Exchange</title>
</head>
<body>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>Register</li>
<li>Log In</li>
</ul>
</nav>
And this is the login.php.
<?php require('connect.php'); ?>
<?php require('headerPublic.php'); ?>
<?php require('session.php'); ?>
<form class="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="inputEmail" >Email address</label>
<input type="email" name="email" placeholder="Email address">
<label for="inputPassword" >Password</label>
<input type="password" name="password" placeholder="Password">
<button name="login" type="submit">Login</button>
</form>
</body>
</html>
<?php
// IF LOGIN BUTTON IS CLICKED:
if (isset($_POST['login']))
{
//LOG IN CODE
}
?>

The search form was missing a closing form tag
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</form>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->

Related

CSS for login form is not loading

Revised question. Trying to make the situation as clear as possible.
I downloaded a login system for my existing website. So as not to mess with my index.php, I set it up in its own folder (login-system). Got it all to work. I copy pasted relevant code to my index.php in the root and changed all paths to "login-system/whatever.php". Even though I changed the paths, it still won't work correctly. Specifically the css. The login form has its own css file (login-system/css/css.html) included like this:
.
In css.html are 3 links (google fonts, normalize and css/style.css)
I cannot get the login form's css AND the existing css (main.css) to work together. I either get my page looking fine and login form has no css or I get the login form with its css messing up my page. What do I need to do?
Here is the relevant code:
The Living Oracles.org
</head>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($_POST['login'])) { //user logging in
require '/login-system/login.php';
}
elseif (isset($_POST['register'])) { //user registering
require '/login-system/register.php';
}
}
?>
<body>
<div class ="login">
<div class="form">
<ul class="tab-group">
<li class="tab">Sign Up
</li>
<li class="tab active">Log In
</li>
</ul>
<div class="tab-content">
<div id="login">
<h1>Welcome Back!</h1>
<form action="index.php" method="post" autocomplete="off">
<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input type="email" required autocomplete="off" name="email"/>
</div>
<div class="field-wrap">
<label>
Password<span class="req">*</span>
</label>
<input type="password" required autocomplete="off" name="password"/>
</div>
<p class="forgot">Forgot Password?
</p>
<button class="button button-block" name="login"/>Log In</button>
</form>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="login-system/js/index.js"></script>
</div>
</div>

Show up a title box,when you click a button

I am wondering if there is a way to show a title box containing a message when you click a button,or as a better example,you have an input,and after php script evalute the value,and it's wrong,a title box will show up , saying "Wrong" ... Any ideas? Just with php if its possible!!
EDIT:
What i am looking for,is not for a simple message like:
echo '<p></p>';
Of course i know how to do that,its basic...
I was just wondering if a TITLE box can show up,like this:
<input type=text title='Wrong'>
but after the value its evaluated...
You could achieve this by setting a GET or POST value with the button:
html:
<form method="post">
<input type="hidden" name="postvalue" value="yes">
</form>
php:
<?php
if(isset($_POST['postvalue'])){
echo "<p>messageboxtoshow</p>";
}
?>
however a solution with javascript would work way better and would look way more userfriendly, and this only works on page refresh.
Try this sample one
<?php
if(isset($_POST['submit'])){
echo "<p> Your message</p>";
}
?>
<form action=<?php $_SERVER['PHP_SELF']?> method="post" >
<input type="submit" name="submit" value="submit">
</form>
Do you mean validation per input field?
You can use JQuery for that.
I made a fiddle to give you a visual idea: http://jsfiddle.net/4b3tzreo/
For example, if this is your form:
<div class="container">
<div class="left">
Username
</div>
<div class="right">
<input type="text" name="username" id="username" />
</div>
</div>
<div class="container">
<div class="left">
Password
</div>
<div class="right">
<input type="password" name="password" id="password" />
</div>
</div>
<div class="container">
<div class="left">
<button id="submit">Submit values</button>
</div>
</div>
You can add a class to it when the input value is empty, like this:
$('#submit').click(function(){
var username = $('#username').val();
var password = $('#password').val()
if(username === '') {
$('#username').addClass('error');
alert('username is not filled');
}
if(password === '') {
$('#password').addClass('error');
alert('password is not filled');
});

How To Make My HTML5 Form Refresh On Its Own?

I have a contact form on my website, and once you click submit button, an echo message comes up but on a new page.
I want the page to automatically refresh when someone clicks submit, but also along with the echo message.
This is the HTML5 Code:
<form method="post" id="form" action="send3.php" class="sendmail" onsubmit="return validateForm()" style="text-align:center;">
<!-- Form Name -->
<center><h2 class="">Contact Us</h2>
</div>
<center><label class="control-label">Your Email Address</label>
<center><input type="text" id="eadd" name="eadd" class="input-xlarge" required>
<center><label class="control-label">Topic of Message</label>
<center><input type="text" id="top" name="top" class="input-xlarge" required>
<center><label class="control-label">Message</label>
<center><textarea id="mess" name="mess" required></textarea>
<Br>
<!-- Button -->
<label class="control-label"></label>
<div class="controls">
<center><input class="btn btn-primary" type="submit">
</div>
</form>
Any Tips/Adivce would be very much appreciated!
Sound like this is what you are looking for...
[myContactPage.php]
if ($_SERVER['REQUEST_METHOD'] == 'POST') //Here you could check other items like referrer or some of your posted fields if you want
{
//do whatever your current send3.php does
//echo the result back out
}
<form method="post" id="myForm" action="myContactPage.php" onsubmit="return validateForm()">
[email field]
[name field]
[message field]
etc...
[submit button]
</form>

How to return php code into html body

I am building a simple form script that collects a users email and returns a PIN.
The input sits in standard HTML below:
<p>
<form class="form-inline" role="form" method="POST">
<div class="form-group">
<label class="sr-only" for="srEmail">Email address</label>
<input type="email" name="srEmail" class="form-control input-lg" id="srEmail" placeholder="Enter email">
</div>
<button type="submit" name="srSubmit" class="btn btn-default btn-lg">Generate PIN</button>
</form>
</p>
I have the following if statement that checks the database to see if the email already exists, and if the user would like a PIN reminder.
if($num_rows != 0) {//if email found in table
?>
Email already registered, would you like a PIN reminder?
<form method="POST" action="">
<input type="submit" name="srSend" value="Click here to get pin reminder" />
<input type="hidden" name="srEmail" value="<?php echo strtolower($email);?>" />
</form>
<?php
exit;
}
At the moment, this returns the result to the user as a new page; how do I put this in the actual HTML of the body page, so it would actually appear below the original form input in a new <p> element?
This is a piece of cake with jquery.post
include the jquery library in your html head and you'll need a short script to get the php content by ajax
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
$('#yourForm').submit(function(e){
e.preventDefault();
var data=$('#yourForm').serialize();
$.post('yourphp.php',data,function(html){
$(body).append(html);
});
});
});
</script>
</head>
<body>
<p>
<form id="yourForm" class="form-inline" role="form" method="POST">
<div class="form-group">
<label class="sr-only" for="srEmail">Email address</label>
<input type="email" name="srEmail" class="form-control input-lg" id="srEmail" placeholder="Enter email">
</div>
<button type="submit" name="srSubmit" class="btn btn-default btn-lg">Generate PIN</button>
</form>
</p>
</body>
You could able to achieve that without ajax too. Simply use a hidden iframe in your main page, then set the target attribute of your form to the iframe as follows:
<form method="post" action="page.php" target="myIframe">
.....
</form>
<p id="theResultP"></p>
<iframe src="#" name="myIframe" style="visibility: hidden"></iframe>
The question now, How could you make the page loaded in the iframe "page.php" to interact with the opener page to update the p. This may be done as follow:
//page.php
<script>
result = parent.document.getElementById('theResultP');
result.innerHtml = "<b>The message you want</b>"
</script>
I dont know if I get what you asking for,but this is my solution :
<p>
<form class="form-inline" role="form" method="POST">
<div class="form-group">
<label class="sr-only" for="srEmail">Email address</label>
<input type="email" name="srEmail" class="form-control input-lg" id="srEmail" placeholder="Enter email">
</div>
<button type="submit" name="srSubmit" class="btn btn-default btn-lg">Generate PIN</button>
</form>
</p>
<?php
if (isset($message)){
<p><?php print $message ?></p>
?>
<?php
}
?>
and in top of your file write something like this :
<?php
if($_post['srSend']){
$message='write your message here';
}
?>

Using "action" in Twitter Boostrap classes

I'm a newbie programmer trying to utilize Twitter Bootstrap to build out a concept. I'm using PHP and assigning actions within HTML tags to POST data and essentially take a user through the navigation. This has been pretty straightforward when using forms: i.e. here is a snippet that does work. For example, for this snippet of HTML:
<form action="?viewnotes" method="post">
<input type="hidden" name="id" value="<?php htmlout($note['id']); ?>">
</form>
It successfully triggers the following if statement in my index.php:
if (isset($_GET['viewnotes']))
However, I'm trying to do the same thing in my registration page, using a Twitter Bootstrap class for buttons. Here is the HTML:
<a class="btn btn-primary btn-large" action="?register">Sign Up Free!ยป</a></p>
The PHP code is:
if (isset($_GET['register']))
{
include 'register.html.php';
}
Clicking on the Sign Up button is not invoking the PHP code. If I hard code the URL it works, but then I have a similar issue on the register.html.php page. HTML on the register page has:
<form class="form-horizontal" action="?storeuser" method="post">
<fieldset>
<legend>It's quick and easy...</legend>
<div class="control-group">
<label class="control-label">First Name</label>
<div class="controls">
<input type="text" name="fname" class="input-xlarge" id="fname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="lname">Last Name</label>
<div class="controls">
<input type="text" name="lname" class="input-xlarge" id="lname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="email">Email Address</label>
<div class="controls">
<input type="text" name="email" class="input-xlarge" id="email">
</div>
</div>
<div class="control-group">
<label class="control-label" name="password">Password</label>
<div class="controls">
<input type="password" name="password" class="input-xlarge" id="password">
</div>
</div>
</fieldset>
<button type="submit" name="action" class="btn btn-primary btn-large">Complete Registration</button>
</form>
However, when clicking on the button, the index file does not trigger the following, which would store the fields into the DB.
if (isset($_GET['storeuser']))
If I hardcode the URL to register.html.php, then the resulting URL looks like localhost/register.html.php?storeuser instead of localhost/?storeuser. I'm not sure if that's affecting the behavior here.
Thank you for the help!
I think you're approaching this the wrong way, and it's not Twitter Bootstrap's fault.
Usually, you'd use POST, not GET, to handle user registrations. Your form would look like this:
<form action="register.php" method="post">
<!-- your form -->
<fieldset>
<input type="submit" name="register" value="Register" class="btn btn-primary" />
</fieldset>
</form>
You can then build register.php as follows:
<?php
if (isset($_POST['register'])) {
// handle user registration
}
// display form
?>
This will display the form when the user visits register.php, but will try and process the user registration first if the form's been POSTed.
try passing a value with your GET variable
<form action="?viewnotes=1" method="post">

Categories