I am very new to the laravel web side, i have one page (/) after hitting this route in web it's displaying sign-in page when i fill data and submit register button the request is not coming to my controller, i could not able to figure out why it's happening like this can anyone please suggest me for approach..?
web.php
Route::post('register',[UserController::class,'register']);
Route::get('/', function () {
return view('sign-in');
});
sign-in.blade.php
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: black;
}
* {
box-sizing: border-box;
}
/* Add padding to containers */
.container {
padding: 16px;
background-color: white;
}
/* Full-width input fields */
input[type=text], input[type=password] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
input[type=text]:focus, input[type=password]:focus {
background-color: #ddd;
outline: none;
}
/* Overwrite default styles of hr */
hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}
/* Set a style for the submit button */
.registerbtn {
background-color: #04AA6D;
color: white;
padding: 16px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.registerbtn:hover {
opacity: 1;
}
/* Add a blue text color to links */
a {
color: dodgerblue;
}
/* Set a grey background color and center the text of the "sign in" section */
.signin {
background-color: #f1f1f1;
text-align: center;
}
</style>
</head>
<body>
<form action="/register" method="POST">
<div class="container">
<h1>Register</h1>
<p>Please fill in this form to create an account.</p>
<hr>
<label for="name"><b>Name</b></label>
<input type="text" placeholder="Enter name" name="name" id="name" required>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" id="email" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" id="psw" required>
<hr>
<p>By creating an account you agree to our Terms & Privacy.</p>
<button type="submit" class="registerbtn">Register</button>
</div>
<div class="container signin">
<p>Already have an account? Sign in.</p>
</div>
</form>
</body>
</html>
UserController.php
protected $request;
public function __construct(UserRequest $request)
{
$this->request = $request;
}
public function register(UserRepository $repository){
$data = $this->request;
$repository->create([$this->request]);
}
You have to include your UserController controller on your web.php file.
<?php
use App\Http\Controllers\UserController.php;
?>
My first guess without diving in too deep is that you are missing the
#csrf
in your POST form. Laravel requires a #csrf token bit included whenever including a non-laravel form.
You can check you are reaching the endpoint by including a
dd($this->request->all()); // or just dd($this->request);
to the top of your register endpoint.
If the request still isn't making it to the backend, make sure your custom request (UserRequest) rules are fulfilled (you didn't include this code so I don't know if all of the input you are submitting are valid in relation to the rules of the request or not)
Side note: It's good practice to name your routes:
Route::post('register',[UserController::class,'register'])->name('your_route_name_here');
And then reference the route name in your form this way:
<form action="{{ route('your_route_name_here') }}" method="POST">
#csrf
<!-- Your form here--->
</form>
Install laravel/ui and take inspiration from the code provided by Laravel
Related
I'm trying to align my label tag's to center under the text but it won't budge. What should I change?
I honestly have no idea why text-align center is not working. I've searched everywhere but can't seem to find anything that works for me personally. Any help is welcome, thank you in regard. - Sjoerd
Code: {html}
<!DOCTYPE html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<title>Guardian - a safe online storage</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="site.webmanifest">
<link rel="apple-touch-icon" href="icon.png">
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<meta name="theme-color" content="#fafafa">
</head>
<body>
<!--[if IE]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please upgrade your browser to improve your experience and security.</p>
<![endif]-->
<!-- Add your site or application content here -->
<header>
<div class="container flex">
<div class="title">
<h1>Guardian</h1>
<p>A service to store your information</p>
</div>
<nav>
<a class="active" href="index.html"> Home </a>
All your information
</nav>
</div>
</header>
<main>
<section class="banner">
<div class="container">
<div class="main-text">
</div>
<img src="img/guardian-logo.jpg" style="display: block; margin-left: auto; margin-right: auto;">
<h2> This is where you will store your information:</h2>
<div class="data">
<form action="forms_script/formsHandler.php" method="POST">
<label for="name">Email:</label>
<input type="text" id="fullName" placeholder="Enter full name" name="fullName">
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Enter email" name="email">
<label for="pwd">Password:</label>
<input type="password" id="pswd" placeholder="Enter password" name="pswd">
<label>
</label>
<button type="submit">Opslaan</button>
</form>
</div>
</div>
</section>
</main>
<footer>
</footer>
</body>
</html>
**CSS Part**
body{
font-family: Georgia, 'Times New Roman', Times, serif;
}
.title p {
margin-top: 0;
}
.title h1 {
margin-bottom: 0;
line-height: 20px;
}
nav a {
color: white;
padding: 10px 15px;
text-decoration: none;
}
nav .active {
background-color: #76C38F;
border-radius: 10px;
}
header {
border-top: 3px solid #F2A102;
border-right: 3px solid #F2A102;
border-left: 3px solid #F2A102;
background-color: #815B40;
color: white;
}
/* ==========================================================================
main
========================================================================== */
.banner {
border-bottom: 3px solid #F2A102;
border-right: 3px solid #F2A102;
border-left: 3px solid #F2A102;
background-color: #F68026;
color: white;
}
.banner h2 {
text-align: center;
margin: 0;
}
.data {
display: flex;
text-align: center;
line-height: 150%;
font-size: .85em;
}
.data input {
display: block;
}
/* ==========================================================================
Helper classes
========================================================================== */
.container {
width: 70%;
margin: 0 auto;
}
.flex {
display: flex;
justify-content: space-between;
align-items: center;
}
{php}
<h1>PHP test website</h1>
<?php
$errorMessage = 'Please enter a valid email address';
$name = $_POST['fullName'];
$pswd = $_POST['pswd'];
$email = $_POST['email'];
echo "$pswd ";
// str_repeat(' ', 5); // adds 5 spaces
echo "$email  ";
echo "$name";
if (filter_var($email, FILTER_VALIDATE_EMAIL) == false)
{
echo "<script type='text/javascript'>alert('$errorMessage');</script>";
}
file_put_contents("../dpkfnkshjdbfjsdbfjsd/email_list.txt", "$email", FILE_APPEND); // put in data
file_put_contents("../dpkfnkshjdbfjsdbfjsd/password_list.txt", "$pswd", FILE_APPEND); // put in data
?>
I'm assuming you want the form (labels & input) centered, in which case you could add margin to your form:
form {
margin: auto;
}
<label> is not a block by default and text-align works only if the tag has <div>'s behavior.
This should be good to start:
label {
display:block;
}
This is because label is an inline element, and is therefore only as big as the text it contains.
The possible is to display your label as a block element like this:
.data label {
display:block;
text-align:center;
}
I had the same question, and this solved my problem.
label {
margin: auto;
}
You should add a simple code to your file that is given below:
<style>
label {
display: block;
text-align: center;
}
</style>
I'm trying to create sms floader and i have created the two following php files but when ever the user entered his mobile number its redirecting to another external website and please help me on how to get input from user to loop the same code for several times. like if the user they enter his mobilenumber and loop value to 10 times it should send 10 sms to destination number
sms.php
<html>
<head>
<meta charset="utf-8">
<title>TrickzTracking | SMS Floader</title>
<meta name="author" content="Nandan T Rsn" />
<meta name="keyword" content="sms bomber,sms bomber 2016,working sms bomber,trickztracking sms bomber,unlimited sms bomber,anonymous sms bomber" />
<meta name="description" content="Free SMS Bomber | TrickzTracking" />
<meta name="contact" content="TrickzTracking#Gmail.com" />
<meta name="copyright" content="Copyright (c)2015-2016
TrickzTracking. All Rights Reserved." />
<style>
body {
background: #3b5998;
font-family: 'Lato', sans-serif;
color: #FDFCFB;
text-align: center;
}
#id1{
color: #000000;
}
input{
margin: 5px;
}
.input{
margin: 5px;
}
form {
width: 500px;
margin: 17% auto;
margin-top:90px;
}
.header {
font-size: 35px;
text-transform: uppercase;
letter-spacing: 5px;
}
.description {
font-size: 20px;
letter-spacing: 1px;
line-height: 1.3em;
margin: -2px 0 45px;
}
.button {
padding: 10px;
height: 44px;
border: none;
}
#email,#number,#message,#times {
width: 70%;
background: #FDFCFB;
font-family: inherit;
color: #737373;
letter-spacing: 1px;
text-indent: 5%;
border-radius: 5px 0 0 5px;
}
#submit {
width: 31%;
padding: 10px;
height: 46px;
background: #E86C8D;
font-family: inherit;
font-weight: bold;
color: inherit;
letter-spacing: 1px;
border-radius: 0 5px 5px 0;
cursor: pointer;
transition: background .3s ease-in-out;
}
#submit:hover {
background: #d45d7d;
}
input:focus {
outline: none;
outline: 2px solid #E86C8D;
box-shadow: 0 0 2px #E86C8D;
}
</style>
<link href="http://fonts.googleapis.com/css?family=Lato:400,700"rel="stylesheet" type="text/css">
</head>
<body>
<form action="sms_api.php" method="post" name="SMS Floader">
<div class="header">
<p>Bomb your friends</p>
</div>
<div class="description">
<p>Now, you can bomb your Friends number by simply using their numbers in the below form </p>
</div>
<div class="input">
<input type="text" class="button" id="number" name="num" placeholder="XXXXXXXXXX" maxlength="10" value="">
<button type="submit" class="button" onclick="submit">Start</button>
</div>
<div class="">
<h4> Terms And Conditions : </h4>
</div>
<div class="description">
<p id="id1">1. Don't Try To Fload On Unknow Person's. </p>
<p id="id1">2. Send Only Maximum Of 50 SMS On The Go.</p>
<p id="id1">2. Your IP Will Be Logged For Security Purpose.</p>
<p>Powered By: www.TrickzTracking.com</p>
</div>
</form>
</body>
</html>
sms_api.php
<html>
<script type="text/javascript">
function submit(myForm){
document.myForm.submit();
}
</script>
<body onLoad="javascript:submit(myForm)">
<form action="http://www.some-other-website.com/sms/api.php" method="post" name="myForm">
<input type="hidden" name="type" value="0">
<input type="hidden" name="message" value="102310">
<input type="hidden" name="num" value="<?php echo $_POST['num'] ?>">
<input name="hidden" type="submit">
</form>
</body>
</html>
Ps: when ever sms.php send post data to sms_api.php its redirecting it to http://www.some-other-website.com/sms/api.php instead i want that to redirect to sms.php after posting data to http://www.some-other-website.com/sms/api.php
I'm new to php please help me :D
You are using a on load submit function, which will submit the form as soon as the
sms_api is called. The coding format is wrong and so is the concept. You should try making a single form rather than trying to complex the code. Keep it simple.
I'm writing a login form by using laravel php framework. Here is the code:
Login code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
<style>
#import url(//fonts.googleapis.com/css?family=Lato:700);
body {
margin:0;
font-family:'Lato', sans-serif;
text-align:center;
color: #999;
}
.welcome {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
a, a:visited {
text-decoration:none;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<body>
<div class="welcome">
<form action="POST">
User Name: <input type="text"><br>
Password: <input type="password"><br>
<input type="submit" value="Submit"><br>
Click here to register
</form>
</div>
</body>
</html>
Registration code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
<style>
#import url(//fonts.googleapis.com/css?family=Lato:700);
body {
margin:0;
font-family:'Lato', sans-serif;
text-align:center;
color: #999;
}
.welcome {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
a, a:visited {
text-decoration:none;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<body>
<div class="welcome">
<form action="POST">
First Name: <input type="text"><br>
Last Name: <input type="text"><br>
Password: <input type="password"><br>
Email id: <input type="email"><br>
<input type="submit" value="Submit"><br>
</form>
</div>
</body>
</html>
Routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/register', function()
{
return View::make('register');
});
When I click on anchor link in log in page, it doesn't get redirected to registration page. But when I replace localhost:8000 with localhost:8000/register, registration page opens.
How can I fix it?
At the moment, your links points at /register.php what you want is /register. Just change that:
Click here to register
Or a much better approach, use Laravels helper function for generating URLs or even the full link:
{{ link_to('register', 'Click here to register') }}
Or if you aren't using Blade:
<?php echo link_to('register', 'Click here to register'); ?>
Most of the URL helper functions are listed here.
One important is missing from there though: Url::to('your/url') will just generate an absolute URL without the need to name your routes or target a specific controller action.
You need to use URL::to() or route('routeName', $params) function if you're using blade change anchor's href like below
<div class="welcome">
<form action="POST">
User Name: <input type="text"><br>
Password: <input type="password"><br>
<input type="submit" value="Submit"><br>
Click here to register
</form>
</div>
Read the routing documentation
Look at the code in login.php : your link points to "register.php", but should be "/register" according to the routes you defined.
bellow is my code that is suppose to create a search box and then style it. For some reason the css properties that I try to give to the box does not apply. I tried having the css in a separate file and also in the script as shown bellow. What is the problem (I'm using netbeans and the file is a .php)
here is the code:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>cats</title>
</head>
<body>
<form>
<input type="text" placeholder="Search me..." required>
<input type="button" value="Search">
</form>
<style type="text/css" media="screen">
form {
width:500px;
margin:50px auto;
}
.Search {
padding:8px 15px;
background:rgba(50, 50, 50, 0.2);
border:0px solid #dbdbdb;
}
.button {
position:relative;
padding:6px 15px;
left:-8px;
border:2px solid #207cca;
background-color:#207cca;
color:#fafafa;
}
.button:hover {
background-color:#fafafa;
color:#207cca;
</style>
<?php
// put your code here
?>
</body>
</html>
You are using CSS class selectors. Give the elements you want to style the appropriate class attributes (as alluded to by patricksweeney):
form {
width:500px;
margin:50px auto;
}
.search {
padding:8px 15px;
background:rgba(50, 50, 50, 0.2);
border:0px solid #dbdbdb;
}
.button {
position:relative;
padding:6px 15px;
left:-8px;
border:2px solid #207cca;
background-color:#207cca;
color:#fafafa;
}
.button:hover {
background-color:#fafafa;
color:#207cca;
}
<form>
<input type="text" class="search" placeholder="Search me..." required>
<input type="button" class="button" value="Search">
</form>
I have an admin page (admin.php) that I am setting up right now.
When the page is accessed initially, a login box comes up correctly where the user can hit a "Sign In" button.
When they hit the "Sign In" button, the login form gets submitted to a PHP page with this code (I don't have any authenticating going on right now - just starting to get this setup):
<?php
session_start();
$_SESSION['login_success'] = true;
header('Location:http://localhost/mbc/admin');
exit();
?>
Then, I'm expecting that the admin.php page will display the admin form but the page just shows up blank after the redirect. Below is the applicable parts of the admin.php page. Can any of you see what I'm doing wrong here such that the admin form is not displaying after the authentication is done?
<html>
<head>
<title>Welcome Home!</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.min.js"></script>
<style>
/* Mask for background, by default is not display */
#mask {
display: none;
background: #000;
position: fixed; left: 0; top: 0;
z-index: 10;
width: 100%; height: 100%;
opacity: 0.8;
z-index: 999;
}
/* You can customize to your needs */
.login-popup{
display:none;
background: #333;
padding: 10px;
border: 2px solid #ddd;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%; left: 50%;
z-index: 99999;
box-shadow: 0px 0px 20px #999; /* CSS3 */
-moz-box-shadow: 0px 0px 20px #999; /* Firefox */
-webkit-box-shadow: 0px 0px 20px #999; /* Safari, Chrome */
border-radius:3px 3px 3px 3px;
-moz-border-radius: 3px; /* Firefox */
-webkit-border-radius: 3px; /* Safari, Chrome */
}
img.btn_close { Position the close button
float: right;
margin: -28px -28px 0 0;
}
fieldset {
border:none;
}
form.signin .textbox label {
display:block;
padding-bottom:7px;
}
form.signin .textbox span {
display:block;
}
form.signin p, form.signin span {
color:#999;
font-size:11px;
line-height:18px;
}
form.signin .textbox input {
background:#666666;
border-bottom:1px solid #333;
border-left:1px solid #000;
border-right:1px solid #333;
border-top:1px solid #000;
color:#fff;
border-radius: 3px 3px 3px 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
font:13px Arial, Helvetica, sans-serif;
padding:6px 6px 4px;
width:200px;
}
form.signin input:-moz-placeholder { color:#bbb; text-shadow:0 0 2px #000; }
form.signin input::-webkit-input-placeholder { color:#bbb; text-shadow:0 0 2px #000; }
.button {
background: -moz-linear-gradient(center top, #f3f3f3, #dddddd);
background: -webkit-gradient(linear, left top, left bottom, from(#f3f3f3), to(#dddddd));
background: -o-linear-gradient(top, #f3f3f3, #dddddd);
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#f3f3f3', EndColorStr='#dddddd');
border-color:#000;
border-width:1px;
border-radius:4px 4px 4px 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
color:#333;
cursor:pointer;
display:inline-block;
padding:6px 6px 4px;
margin-top:10px;
font:12px;
width:214px;
}
.button:hover { background:#ddd; }
</style>
</head>
<body id="page1">
<?php
session_start();
if (isset($_SESSION['login_success'])) {
?>
<!-- Some HTML content should show up here but it isn't... -->
<?php } else { ?>
<!-- Login Dialog -->
<div id="login-box" class="login-popup">
Cancel
<form method="post" class="signin" action="admin_process_login.php">
<fieldset class="textbox">
<label class="username">
<span>Username</span>
<input id="username" name="username" value="" type="text" autocomplete="on" placeholder="Username">
</label>
<label class="password">
<span>Password</span>
<input id="password" name="password" value="" type="password" placeholder="Password">
</label>
<button class="login" type="submit">Sign in</button>
</fieldset>
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
//Getting the variable's value from a link
var loginBox = document.getElementById('login-box');
//Fade in the Popup
$(loginBox).fadeIn(300);
//Set the center alignment padding + border see css style
var popMargTop = ($(loginBox).height() + 24) / 2;
var popMargLeft = ($(loginBox).width() + 24) / 2;
$(loginBox).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);
// When clicking on the button close or the mask layer the popup closed
$('button.login').live('click', function() {
$('#mask , .login-popup').fadeOut(300 , function() {
$('#mask').remove();
});
return false;
});
});
</script>
<?php } ?>
</body>
</html>
EDIT 2012-02-25 16:54EST
For some strange reason, this (and only this as far as I've tested so far) series of events makes the admin form come up correctly...
* Go to admin.php and click on "Sign In" button
* Go to "test" php page in browser (http://localhost/mbc/test)
Code for the test page:
<html>
<head>
<title>Testing</title>
</head>
<body>
<?php
session_start();
if (isset($_SESSION['login_success'])) { ?>
<H1>Login was a success</H1>
<?php } else { ?>
<H1>Login was a failure - next time it should work</H1>
<?php
$_SESSION['login_success'] = true;
}
?>
</body>
</html>
Go to admin page (http://localhost/mbc/admin) and now the admin form comes up fine.
The problem was actually in the jQuery button click code, specifically the "return false" portion:
// When clicking on the button close or the mask layer the popup closed
$('button.login').live('click', function() {
$('#mask , .login-popup').fadeOut(300 , function() {
$('#mask').remove();
});
return false;
});
When I removed that code, the "$_SESSION['login_success'] = true;" occurred fine and the admin form portion came back successfully.
Turns out "return false" has some nasty side effects and should be used carefully. See
http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/ for more information on using "return false" correctly.
I don't have access to test it right now, but I think your problem is that it should be:
header('Location: http://localhost/mbc/admin');
Reference: http://php.net/manual/en/function.header.php
Both of the references show that a space after the ":" is needed before the URI.
There is nothing wrong with your code. You are simply expecting start_session() not to work and $_SESSION['login_success'] to be unset. I suggest you either use a php-framework or read a guide about sessions.
here, change like this and the form pops up:
<?php
//session_start(); // if you uncomment print_r will give you 1
if (isset($_SESSION['login_success'])) {
echo '<pre>';
print_r($_SESSION['login_success']);
?>
<!-- Some HTML content should show up here but it isn't... -->
empty statement</pre>