I am trying to use select2 for my laravel Create function. but it does nothing, and i followed multiple tutorials with the same results.
index.blade(my scripts are in the header)
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<title>Subfolders</title>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" integrity="sha512-nMNlpuaDPrqlEls3IX/Q56H36qvBASwb3ipuo3MxeWbsQB1881ox0cRv7UPTgBlriqoynt35KjEwgGUeUXIPnw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js" integrity="sha512-2ImtlRlf2VVmiGZsjm9bEyhjGW4dU7B6TNwh/hx/iSByxNENtj3WVE6o/9Lj4TJeVXPi4bnOIMXFIJJAeufa0A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
#stack('page_scripts')
</head>
#include('admin.file.create')
here i include the 'create.blade' file
create.blade:
<div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Add File</h1>
<div>
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div><br />
#endif
<form method="post" action="{{ route('admin.file.store') }}" enctype="multipart/form-data">
#csrf
<div class="form-group">
<label for="title">{{('title')}}*</label>
<input type="text" class="form-control" name="title" />
</div>
<div class="form-group">
<label for="value">{{('Short description')}}</label>
<input type="text" class="form-control" name="description_short" />
</div>
<div class="form-group">
<label for="name">{{('Tags')}}*</label>
<select id="tag_ids" name="tag_id[]" class="form-control" multiple>
<option value="">{{('Select Tags')}}</option>
#foreach($tags as $tag)
<option value=" {{$tag->id}}">{{$tag->name}}</option>
#endforeach
</select>
</div>
<p>* required</p>
<button type="submit" class="btn btn-primary">Add File</button>
</form>
</div>
</div>
</div>
#push('page_scripts')
<script>
$(document).ready(function() {
$('#tag_ids').select2();
});
</script>
#endpush
image of the select:
if i need to upload any more information i will gladly do so!
You need to add jQuery CDN and call the select2 function. I have attached a sample code below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Select2</title>
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/select2#4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
</head>
<body>
<select class="js-example-basic-single" name="state">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
<!-- JS -->
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2#4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function () {
$('.js-example-basic-single').select2();
});
</script>
</body>
</html>
Related
I am learning PHP, and would like to know if there is any way to hide an option depending on what I get,
basiccaly this is my code it's simple.
<?php
require 'database.php';
session_start();
if(!isset($_POST['update'])){
$id=$_GET['id'];
$state=$_GET['state'];
$sql="SELECT * from states";
$show=$conn->prepare($sql);
$show->execute();
$result = $show->fetchAll(PDO::FETCH_ASSOC);
}else{
$id=$_POST['id'];
$state=$_POST['state'];
$sql="UPDATE pqrs SET fk_state=:fk_state WHERE idPqrs=:id";
$update=$conn->prepare($sql);
$update->bindParam(':id',$_POST['id']);
$update->bindParam(':fk_state',$_POST['state']);
$update->execute();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<body>
<div class="ml-5"><?php require 'partials/header.php' ?></div>
<div class="container col-5">
<h1 class="text-center mb-5">Extreme Techonologics</h1>
<h2 class="text-center">Ingrese los campos a cambiar</h2>
<form action="pqr_update.php" method="POST">
<div class="form-group">
<input type="hidden" value="<?php echo $id?>" class="form-control" name="id">
</div>
<div class="form-group my-5">
<label for="pqr_type">Seleccione el estado del PQR:</label>
<select class="form-control" id="state" name="state">
<?php foreach($result as $state):?>
<option value="<?php echo $state['idState'];?>"><?php echo $state['state'];?></option>
<?php endforeach ?>
</select>
</div>
<button type="submit" class="btn btn-primary" name="update">Enviar</button>
</form>
</div>
Cerrar Sesión
</body>
</html>
</html>
Basically I would like to know if when $ _GET = ['state'] = 'Nuevo', when I press the button (name = 'update') what I receive from the POST, it only shows me an option (En Ejecución), in theory there are 3 states , Nuevo, En Ejecución and Cerrado. When the status is ¿Nuevo' I don't want it to show me the option "EN Ejecucuion" and when the option received is "EN Ejecucuion" I do not want it to show me the option 'Nuevo'.
Based on the above requirement, try this:
<?php
require 'database.php';
session_start();
if(!isset($_POST['update'])){
$id=$_GET['id'];
$state=$_GET['state'];
$sql="SELECT * from states";
$show=$conn->prepare($sql);
$show->execute();
$result = $show->fetchAll(PDO::FETCH_ASSOC);
}else{
$id=$_POST['id'];
$state=$_POST['state'];
$sql="UPDATE pqrs SET fk_state=:fk_state WHERE idPqrs=:id";
$update=$conn->prepare($sql);
$update->bindParam(':id',$_POST['id']);
$update->bindParam(':fk_state',$_POST['state']);
$update->execute();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<body>
<div class="ml-5"><?php require 'partials/header.php' ?></div>
<div class="container col-5">
<h1 class="text-center mb-5">Extreme Techonologics</h1>
<h2 class="text-center">Ingrese los campos a cambiar</h2>
<form action="pqr_update.php" method="POST">
<div class="form-group">
<input type="hidden" value="<?php echo $id?>" class="form-control" name="id">
</div>
<div class="form-group my-5">
<label for="pqr_type">Seleccione el estado del PQR:</label>
<select class="form-control" id="state" name="state">
<?php
foreach($result as $state):
if (
($_REQUEST['state'] == '¿Nuevo\'' && $state['state'] != 'EN Ejecucuion')
&&
($_REQUEST['state'] == 'EN Ejecucuion' && $state['state'] != '¿Nuevo\'')
):
?>
<option value="<?php echo $state['idState'];?>"><?php echo $state['state'];?></option>
<?php endif; endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-primary" name="update">Enviar</button>
</form>
</div>
Cerrar Sesión
</body>
</html>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
<meta name="author" content="GeeksLabs">
<meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
<link rel="shortcut icon" href="img/favicon.png">
<title>welcome</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<link href="css/elegant-icons-style.css" rel="stylesheet" />
<link href="css/font-awesome.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet">
<link href="css/style-responsive.css" rel="stylesheet" />
</head>
<body class="login-img3-body">
<div class="container">
<form class="login-form" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="login-wrap">
<p class="login-img"><i class="icon_lock_alt"></i></p>
<div class="input-group">
<span class="input-group-addon"><i class="icon_profile"></i></span>
<input type="text" name="Username" class="form-control" placeholder="Username" autofocus>
</div>
<div class="input-group">
<span class="input-group-addon"><i class="icon_key_alt"></i></span>
<input type="password" name="password" class="form-control" placeholder="Password">
</div>
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
<span class="pull-right"> Forgot Password?</span>
</label>
<button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
<button class="btn btn-info btn-lg btn-block" type="submit">Signup</button>
</div>
</form>
<div class="text-right">
<div class="credits">
Developer::prakash
</div>
</div>
</div>
</body>
</html>
Its my blade file ,but it cant work properly how can i do it workable ?? i think it problem on action="{{ route('login') }} when i click login bottom it shows
Whoops, looks like something went wrong.
MethodNotAllowedHttpException in RouteCollection.php line 251: How can i solve this??
You are missing method='post', I hope you have declared the route correctly in routes.php
Route::post('/post-form', 'YourController#saveDataFunction'); declare the route properly, if the method is GET write it as Route::GET else this would work fine.
MethodNotAllowedHttpException clearly means the route is not found, means it's missing in the collection OR you declared it differently.
If you don't specify method attribute GET is assumed. This exception means that Laravel couldnot find the specified route.
Which in your case appears to be that you have declared a post route in your routes/web.php file.
Either, edit your web.php file OR specify a method="post" attribute on your form.
I have the below php page, which is a holding page with a contact form:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<!--<link rel="icon" href="../../favicon.ico">-->
<title>Coming Soon</title>
<!-- Bootstrap -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<link href="assets/css/bootstrap-theme.css" rel="stylesheet">
<link href="assets/css/font-awesome.css" rel="stylesheet">
<!-- siimple style -->
<link href="assets/css/style.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>TEST</h1>
<h2 class="subtitle">We're working hard to improve our website and we'll be ready to launch soon
<h2 class="subtitle">Feel free to contact us below with any enquiries</h2>
<p>
<?php
$name = $_POST["contactname"];
?>
<form class="Contact" method="post" action="">
<label class="alignleft">Name</label>
<input type="text" name="contactname" id="contactname" placeholder="Enter Name">
<label class="alignleft">Email</label>
<input name="Email" placeholder="Email Address">
<label class="alignleft">Enquiry</label>
<textarea name="Enquiry" placeholder="Your enquiry"></textarea><br>
<input id="submit" name="submit" type="submit" value="Submit!" class="btn btn-theme">
</form>
<div class="social">
<i class="fa fa-facebook" aria-hidden="true"></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
<!--<i class="fa fa-google-plus" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>-->
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
</body>
</html>
Within the php section I am trying to read the values of the input boxes, however even with only
$_POST["contactname"];
the website returns a 500 Internal Server Error. If i remove that line and replace with a simple:
echo "Test";
Then the site works and displays "Test"
If there something I am missing with the assigning of the variable from the input box?
You should make sure the key of the POST array is set and then validate your values first before you show them, and be sure to handle errors and invalid values!
if(isset($_POST["contactname"])){
// Do validation, like making sure its not a empty string
if (!empty($_POST["contactname"])) {
echo $_POST["contactname"];
} else {
echo "A validation error";
}
}
Also enable PHP error output which will greatly help you debug issues like this:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
And display_errors = on in your php.ini to make PHP show parse errors.
I would recommend using a second file to process the form instead of having it all on one page. Not only does it make your code look cleaner but I find it can also help with debugging. So it will look something like this:
index.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<!--<link rel="icon" href="../../favicon.ico">-->
<title>Coming Soon</title>
<!-- Bootstrap -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<link href="assets/css/bootstrap-theme.css" rel="stylesheet">
<link href="assets/css/font-awesome.css" rel="stylesheet">
<!-- siimple style -->
<link href="assets/css/style.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>TEST</h1>
<h2 class="subtitle">We're working hard to improve our website and we'll be ready to launch soon
<h2 class="subtitle">Feel free to contact us below with any enquiries</h2>
<form class="Contact" method="post" action="form_process.php">
<label class="alignleft">Name</label>
<input type="text" name="contactname" id="contactname" placeholder="Enter Name">
<label class="alignleft">Email</label>
<input name="Email" placeholder="Email Address">
<label class="alignleft">Enquiry</label>
<textarea name="Enquiry" placeholder="Your enquiry"></textarea><br>
<input id="submit" name="submit" type="submit" value="Submit!" class="btn btn-theme">
</form>
<div class="social">
<i class="fa fa-facebook" aria-hidden="true"></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
<!--<i class="fa fa-google-plus" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>-->
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
</body>
</html>
form_process.php:
<?php
if(isset($_POST['contactname'])
{
$name = $_POST['contactname'];
if(empty($name))
{
die("contact name is empty")
}
else
{
echo $name;
}
}
// Continue processing form data
?>
I would also follow the recommendations from other users about displaying PHP errors.
You should validate it first
if(isset($_POST['contactname'])){
// Do your post handling
}
Firstable , you need to check if $_POST is defined , and not empty :
if(isset($_POST["contactname"]) && !empty($_POST["contactname"])){
echo $_POST["contactname"];
}
Second , i think you need to configure you'r server to show errors and not to redirect you to 500 error:
Just modify your php.ini with this line:
display_errors = on
Hi guy I'm new to php and I have a php form as shown below, it used to work before I applied bootstrap to it.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Login Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" href="css/login.css" rel="stylesheet" />
<link type="text/css" href="css/bootstrap/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<!-- Main Container -->
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<h1 class="text-center login-title">Sign in to HRMS</h1>
<div class="account-wall">
<img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=120"
alt="">
<form class="form-signin" method="post" action="">
<input type="text" id="txtEmpID" class="form-control" placeholder="Employee ID" required autofocus>
<input type="password" id="txtEmpPass" class="form-control" placeholder="Password" required>
<button id="btnLogin" class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var login_url = "<?php echo Util::convertLink("Login") ; ?>" ;
<?php include (PATH_CODE . "js/general/login.min.js") ; ?>
</script>
</body>
</html>
with the button Login bind to a method in login.js
$(document).ready(function()
{
$('#btnLogin').button().bind('click',this,onLogin) ;
}) ;
function onLogin(obj) {
alert( $('#txtEmpID').val());
}
it there something i'm missing?
$(document).ready(function()
{
$('#btnLogin').bind({
click: function() {
onLogin(this);
}
});
});
function onLogin(obj) {
alert( $('#txtEmpID').val());
}
DEMO
I have a simple login page with 2 textfields and a button. When I press "Submit", the URL changes to the php page but I see absolutely nothing at all. I have no idea how to fix it so I'm hoping somebody can help me.
My HTML page:
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="style2.css" />
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<link rel="stylesheet" href="themes/customtheme.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<a class="ui-btn-left" href="index.html" data-icon="back">Back</a>
<h1><span>Login</span></h1>
<a class="ui-btn-right" href="#" data-icon="info">i & €</a>
</div>
<div data-role="content" data-position="relative">
<div class="loginform">
<form id="loginForm" action="login.php" method="POST">
<span>Email adress:</span>
<input type="text" name="email" id="email"></input>
<span>Password:</span>
<input type="password" name="password" id="password"></input>
<input type="submit" value="Login" />
</form>
</div>
</div>
<div data-role="footer" data-position="fixed"></div>
</div>
</body>
</html>
And my login.php:
<?php session_start();
error_reporting(E_ALL);
ini_set('display_errors',TRUE);
ini_set('display_startup_errors',TRUE);
echo ("Test");
?>
I don't even see 'Test' nor any error...
Its actually not a php problem. Assume you are using JQuery mobile. Disabling data-ajax may help.
<script type="text/javascript">
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
</script>
Use this code on your html page.