That is the error how do I fix it? Thats all of the code and I am confused with PHP. The template I have auto makes the error logs so I saw this and I can't access profile.php. Please help!
<?php
require_once('./pieces/header.php');
?>
<div class="row">
<div class="col-sm-8" id="center">
<div class="panel panel-default">
<div class="panel-heading">Profile Editor</div>
<div class="panel-body">
<form method="POST">
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-github-alt"></i></span>
<input type="text" class="form-control" value="<?php $user>getUsername(); ?>" title="Account username." disabled />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" class="form-control" value="<?php $user>getEmail(); ?>" title="Account email." disabled />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-trophy"></i></span>
<input type="text" class="form-control" value="<?php $user>getMembership(); ?>" title="Account membership." disabled />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-key"></i></span>
<input type="password" name="oldpassword" class="form-control" placeholder="Current Password" title="Current account password." value="" maxlength="32" autocomplete="off" />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-key"></i></span>
<input type="password" name="password" class="form-control" placeholder="New Password" value="" title="New account password." maxlength="32" autocomplete="off" />
</div>
<div class="form-group no-margn">
<input type="submit" name="save" class="btn btn-success btn-block" value="Save Changes"/>
</div>
</form>
</div>
</div>
</div>
Your sintaxe is wrong.
Your:
<?php $user>getUsername(); ?>
Correct:
<?php $user->getUsername(); ?>
In Drupal 9, getUsername is depreciated. Reference here.
It is recommended to use getAccountName or getDisplayName instead.
The error 'undefined function' is self explanatory, it means the function you are trying to call does not exist. Your post has the function "getusername()" while your code snippet has the function "getUsername()". Please not the uppercase "U" in the snippet and remember that php is a case sensitive language.
Thanks
Related
Cannot seem to get this working - Will only work with styling gone. Is there any reason why I cannot get it to working whilst styling is left in? Are there any particular settings I need to change? I've tried most things suggested online, but it still wont work. I've been at this for hours now.
<?php
if(isset($_POST['register'])) {
echo "Working";
}
?>
<form method="post" action="register.php">
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputFirstName" type="text" placeholder="Enter your first name" />
<label for="inputFirstName">First name</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input class="form-control" id="inputLastName" type="text" placeholder="Enter your last name" />
<label for="inputLastName">Last name</label>
</div>
</div>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="inputEmail" type="email" placeholder="name#example.com" />
<label for="inputEmail">Email address</label>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputPassword" type="password" placeholder="Create a password" />
<label for="inputPassword">Password</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputPasswordConfirm" type="password" placeholder="Confirm password" />
<label for="inputPasswordConfirm">Confirm Password</label>
</div>
</div>
</div>
<div class="mt-4 mb-0">
<div class="d-grid">
<a class="btn btn-primary btn-block" type="submit" name="register" id="register"> Create Account</a>
</div>
</div>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="js/scripts.js"></script>
</body>
</html>
You have to fix small mistake to make it run. For example
Wrong:
<a class="btn btn-primary btn-block" type="submit" name="register" id="register"> Create Account</a>
Right:
<input class="btn btn-primary btn-block" type="submit" name="register" id="register" value="Create Account">
OR
<button class="btn btn-primary btn-block" type="submit" name="register" id="register"> Create Account</button>
You can use A Tag to submit a form but that is totally different thing. This post will help you in case you want it: a tag as a submit button?
Here is the complete working version of your code
<?php
if(isset($_POST["register"])) {
echo "Working";
}
?>
<form method="post" action="">
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputFirstName" type="text" placeholder="Enter your first name" />
<label for="inputFirstName">First name</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input class="form-control" id="inputLastName" type="text" placeholder="Enter your last name" />
<label for="inputLastName">Last name</label>
</div>
</div>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="inputEmail" type="email" placeholder="name#example.com" />
<label for="inputEmail">Email address</label>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputPassword" type="password" placeholder="Create a password" />
<label for="inputPassword">Password</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputPasswordConfirm" type="password" placeholder="Confirm password" />
<label for="inputPasswordConfirm">Confirm Password</label>
</div>
</div>
</div>
<div class="mt-4 mb-0">
<div class="d-grid">
<button class="btn btn-primary btn-block" type="submit" name="register" id="register"> Create Account</button>
</div>
</div>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="js/scripts.js"></script>
</body>
</html>
First of all, replace the label tags with input tags. These do not cause any problems, just the way you wrote is unusual and irregular.
Second, you have to write the register button with the button or input tag, and this is your main problem.
or
<button class="btn btn-primary btn-block" type="submit" name="register" id="register"> Create Account</button>
I have a register/log in page with POST method. this is the form.php:
<form method="POST" action="process.php">
<div class="section">
<div class="container">
<div class="row full-height justify-content-center">
<div class="col-12 text-center align-self-center py-5">
<div class="section pb-5 pt-5 pt-sm-2 text-center">
<h6 class="mb-0 pb-3"><span>Log In </span><span>Sign Up</span></h6>
<input class="checkbox" type="checkbox" id="reg-log" name="reg-log"/>
<label for="reg-log"></label>
<div class="card-3d-wrap mx-auto">
<div class="card-3d-wrapper">
<div class="card-front">
<div class="center-wrap">
<div class="section text-center">
<h4 class="mb-4 pb-3">Log In</h4>
<div class="form-group">
<input type="text" name="username" class="form-style" placeholder="username" id="Username" autocomplete="off">
<i class="input-icon uil uil-at"></i>
</div>
<div class="form-group mt-2">
<input type="password" name="password4" class="form-style" placeholder="password" id="password4" autocomplete="off">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<button name="login" id="login" class="btn mt-4">Log in</button>
<p class="mb-0 mt-4 text-center">Forgot your password?</p>
</div>
</div>
</div>
<div class="card-back">
<div class="center-wrap">
<div class="section text-center" style="padding-top: 2.5rem;">
<h4 class="mb-2 pb-3">Sign Up</h4>
<div class="form-group">
<input type="text" name="username" class="form-style" placeholder="Username" id="username" autocomplete="off">
<i class="input-icon uil uil-user"></i>
</div>
<div class="form-group mt-2" style="padding-top: 2.5rem;">
<input type="email" name="email" class="form-style" placeholder="Email" id="email" autocomplete="off">
<i class="input-icon uil uil-at"></i>
</div>
<div class="form-group mt-2" style="padding-top: 2.5rem;">
<input type="password" name="password" class="form-style" placeholder="Password" id="password" autocomplete="off">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<div class="form-group mt-2" style="padding-top: 2.5rem;">
<input type="password" name="password2" class="form-style" placeholder="Repeat Password" id="password2" autocomplete="off">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<button name="register" id="register" class="btn mt-4">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
In my process.php i have:
if(isset($_POST['register'])){
...do the register
}
and it works just fine.
I coded the login and it did not worked. I figured out that $username = $_POST['username'] and $password= $_POST['password'] are just empty. So i tried this just to see if they take any values:
if(isset($_POST['login'])){
echo $_POST['username']
}
and it is just blank.
A quick fix, change the IDs in your login section inputs from this:
<input type="text" id="username">
<input type="password" id="password4">
To this:
<input type="text" id="loginUsername">
<input type="password" id="loginPassword">
You can then check them in your process.php file by doing the following:
if (isset($_POST['login'])) {
echo 'Username: ' .$_POST['loginUsername']. ' Password: '. $_POST['loginPassword'];
}
As another commenter has mentioned, having two separate forms would also solve the problem.
I am trying to add records to the database using laravel. When I click on register, I am redirected to a nee page but I get an error saying page has expired due to inactivity. The record isn't inserted into the database.
The files are as follows:
register.blade.php
<form action="/registers" method="post">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="form-group has-feedback">
<input type="text" class="form-control" name="username" placeholder="Full name">
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="email" class="form-control" name="email" placeholder="Email">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="number" class="form-control" name="contact" placeholder="Contact Number">
<span class="glyphicon glyphicon-earphone form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" name="pass" placeholder="Password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" name="secondpass" placeholder="Retype password">
<span class="glyphicon glyphicon-log-in form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> I agree to the terms
</label>
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Register</button>
</div>
<!-- /.col -->
</div>
routes.php
Route::get('/register', 'mainController#register');
Route::post('/registers','mainController#registration');
mainController.php
public function register(){
return view('register');
}
public function registration(Request $request){
$username = $request->input('username');
$email = $request->input('email');
$contact = $request->input('contact');
$password = $request->input('secondpass');
$data=array("username"=>$username,"email"=>$email,"contact"=>$contact,"password"=>$password);
DB::table('users')->insert($data);
return Redirect::back();
}
Add CSRF token to the form:
{{ csrf_field }}
In Laravel 5.6+:
#csrf
I am wrapping functions in php pages in the functions.php and to access these pages, i put an action and a value in the url. I also have a function_calls.php which requests the action and its value and passes it to a switch case which calls the appropriate function. The problem i have is that i case i want to edit a field . I dont have an appropriate case(for the switch) which i want to look something like admin.php?action=edit?id=some_id.
function_calls.php
<?php
require_once "functions.php";
if (isset($_REQUEST['action'])) {
$option = $_REQUEST['action'];
echo $option;
switch ($option) {
case "complaints":
complaint();
break;
case "users":
users();
break;
case "officers":
officers();
break;
case "register_officer":
register_officer();
break;
case "register_student":
register_student();
break;
case "add_event":
add_event();
break;
default:
complaint();
break;
}
} else {
echo '<div class="jumbotron">
<h1>Welcome To The Administration Panel </h1>
<p>You can manage accounts and view the complaints here.</p>
</div>';
}
functions.php
<?php
include_once "include/db_connect.php";
function register_student()
{
?>
<section>
<div class="row">
<div class="col-md-7 col-md-offset-1">
<form class="" method="post" action="">
<div class="row">
<div class="col-md-6 ">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Firstname" name="firstname" required=""
class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Lastname" name="lasttname" required=""
class="form-control">
</div>
</div>
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" placeholder="Email" name="email" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Registration Number" name="reg_no" required=""
class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-phone"></i></span>
<input type="text" placeholder="Phone" name="phone" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Password" name="password" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Confirm Password" name="conf_password" required=""
class="form-control">
</div>
<div class="row">
<!--<div class="col-md-6 checkbox">
<label><input type="checkbox">Remember me</label>
</div>-->
<div class="col-md-12">
<button class="btn btn-success btn-block pull-right" type="submit" name="register">Register
Student
</button>
</div>
</div>
</form>
</div>
</div>
</section>
<?php
}
function register_officer()
{
?>
<section>
<div class="row">
<div class="col-md-7 col-md-offset-1">
<form class="" method="post" action="register.php">
<div class="row">
<div class="col-md-6 ">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Firstname" name="firstname" required=""
class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Lastname" name="lastname" required=""
class="form-control">
</div>
</div>
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" placeholder="Email" name="email" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Rank" name="rank" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-phone"></i></span>
<input type="text" placeholder="Phone" name="phone" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Password" name="password" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Confirm Password" name="conf_password" required=""
class="form-control">
</div>
<div class="row">
<!--<div class="col-md-6 checkbox">
<label><input type="checkbox">Remember me</label>
</div>-->
<div class="col-md-12">
<button class="btn btn-success btn-block pull-right" type="submit" name="register_officer">
Register Officer
</button>
</div>
</div>
</form>
</div>
</div>
</section>
<?php
}
This would be a bit more elegant solution than yours:
<?php
require_once 'functions.php';
if (isset($_GET['action'])) {
$option = $_GET['action'];
echo $option;
if(in_array($option, get_defined_functions()['user']) === true) {
call_user_func($option);
} else {
complaint();
}
} else {
echo '<div class="jumbotron">
<h1>Welcome To The Administration Panel </h1>
<p>You can manage accounts and view the complaints here.</p>
</div>';
}
So then you can define a function edit() which will be automatically called by the call_user_func without altering the switch each time you add a new function.
I have a form like below:
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].title" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].isbn" placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0].price" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="button" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
How to get value of this form in php $_Post because the name of fields are like <br/>name="book[0].title"**<br/>?
and there are many dynamic different name input fields.
If you can use for multiple books then use book[0].title like below,
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
If you want to use same form then change name of all textbox like,
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][isbn]." placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0][price]" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="submit" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
And get value of this form like echo $_POST['book'][0]['title'];
I hope this can help you.
You need to change name attribute,
<div class="col-xs-4">
<input type="text" class="form-control" name="book_title" placeholder="Title" />
</div>
book[0].title, this is not valid name.
You can now get something like this,
$_POST['book_title']