I am still looking forward to getting this solved. The simple thing to be done is to use autocomplete in an input form control, to my surprise it not puling the records from into the text input. If I query the result through the browser, I do see the results thus:
http://localhost:2222/json/redirects/
I do see this result:
[{"id":null,"value":"Andorra"},{"id":null,"value":"United Arab Emirates"},{"id":null,"value":"Afghanistan"},{"id":null,"value":"Antigua and Barbuda"},{"id":null,"value":"Anguilla"},{"id":null,"value":"Albania"},{"id":null,"value":"Armenia"},{"id":null,"value":"Netherlands Antilles"},{"id":null,"value":"Angola"},{"id":null,"value":"Antarctica"},
This is the blade file:
<!DOCTYPE html>
<html>
<head>
{!! Html::style('bootstrap/css/bootstrap.css') !!}
{!! Html::style('bootstrap/css/bootstrap.min.css') !!}
<link href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" media="all" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<section class="panel panel-default">
<header class="panel-heading">
<input type="text" name="searchname" id="searchname" class="form-control" placeholder="enter name">
</header>
<div class="panel-body">
<table>
<tr>
<td><input type="text" name="id" id="id" class="form-control" placeholder="ID" ></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td><input type="text" name="name" id="name" class="form-control" placeholder="Name" ></td>
</tr>
</table>
</div>
</section>
</div>
</div>
</body>
<script type="text/javascript">
$('#searchname').autocomplete({
source: '{!! Url::route('jsonRedirect') !!}',
minlength: 1,
autofocus: true,
select: function(e, ui){
alert(ui);
}
});
</script>
</html>
This is the controller:
public function SelectLocationPlaces(Request $userAdressRequest)
{
$term = $userAdressRequest->term;
$data = Country::where('name', 'LIKE', '%'.$term.'%')->take(10)->get();
$results = array();
foreach ($data as $key => $value) {
$results[] = ['id'=>$value->id, 'value'=>$value->name];
}
return response()->json($results);
}
This is the route:
Route::get('json/redirects', array('as'=>'jsonRedirect', 'uses'=>'UserAddressController#SelectLocationPlaces'));
Error log:
<body>
<div id="sf-resetcontent" class="sf-reset">
<h1>Whoops, looks like something went wrong.</h1>
<h2 class="block_exception clear_fix">
<span class="exception_counter">1/1</span>
<span class="exception_title"><abbr title="Symfony\Component\Debug\Exception\FatalErrorException">FatalErrorException</abbr> in <a title="C:\Users\ken4ward\Documents\xampp\htdocs\tradersmart\storage\framework\views\d12352064f8db7567c7110c110aa0321 line 39" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">d12352064f8db7567c7110c110aa0321 line 39</a>:</span>
<span class="exception_message">Class 'Url' not found</span>
</h2>
<div class="block">
<ol class="traces list_exception">
<li> in <a title="C:\Users\ken4ward\Documents\xampp\htdocs\tradersmart\storage\framework\views\d12352064f8db7567c7110c110aa0321 line 39" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">d12352064f8db7567c7110c110aa0321 line 39</a></li>
</ol>
</div>
Please,kind hearts, what could be the reason why the autocomplete not working but yet I can view the json response on the url?
Thanks, everyone. It's finally working. It was caused by passing the wrong URL format as the source. So, all I changed is this:
From: source: '{!! Url::route('jsonRedirect') !!}',
To: '{{ url('json/redirects') }}',
Related
I'm attempting to display a message in red colour if the data already exists in the database but it doesn't seem to be working. This is the code that I'm using.
PHP code:
<?php
/**
* Template Name: Add IP Address
*/
get_header();
?>
<?php
$sql="SELECT * FROM `wp_5wbtdj_ip_based_login` where (start='$start' or end='$end');";
$res=mysqli_query($mysqli,$sql);
if (mysqli_num_rows($res) > 0) {
$row = mysqli_fetch_assoc($res);
if($end==isset($row['end']))
{
echo " End IP already exists";
}
if($start==isset($row['start']))
{
echo "Start IP already exists";
}
}
else{
//do your insert code here or do something (run your code)
}
If($_POST['Submit']){
global $wpdb;
$username = $_POST['username'];
$start = ip2long($_POST['start']);
$end = ip2long($_POST['end']);
If($wpdb ->insert('wp_5wbtdj_ip_based_login',
array(
'username' => $username,
'start' => $start,
'end' => $end
)
)== false) wp_die ('<div class="errormessage">Database insertion failed </div>');
else echo '<div class="successmessage"> Database insertion successfull </div>';
?>
<?php
}
else{
}
?>
HTML code:
<main role="main">
<div class="section section_white section_nopadding_top">
<div class="container">
<div class="row">
<div class="col-md-12">
<br><br>
<div class="wrap">
<form action="" id="postjob" method="post">
<h3 style="margin-left:50px;">IP Based Login</h3>
<hr />
<h4 style="margin-left:50px;">Add IP Range</h4>
<table class="form-table" style="margin-left:50px;">
<tr>
<th scope="row" valign="top">
<label for="username">Username</label><br />
</th>
<td>
<input type="text" size="25" name="username" value="<?php echo do_shortcode('[show_loggedin_as]'); ?>"><br /><br>
</td>
</tr>
<tr>
<div class="wrapper">
<th scope="row" valign="top">
<label for="start_ip">Start IP </label>
</th>
<td>
<input type="text" minlength="7" maxlength="15" size="25" pattern="^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$" name="start" valign="top" required>
</div>
<br><br>
<tr>
<div class="wrapper">
<th scope="row" valign="top">
<label for="start_ip">End IP</label>
</th>
<td>
<input type="text" minlength="7" maxlength="15" size="25" pattern="^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$" name="end" valign="top" required>
</div>
</td>
</tr>
<br>
</table><br />
<input name="Submit" class="button" value="Add IP range" type="Submit" style="margin-left:50px;" />
</form>
</div>
<br /><br />
</div> <!-- /col-md-12 -->
</div> <!-- /row -->
</div><!-- /.container -->
</div> <!-- /section -->
</main><!-- /.container -->
</div>
<?php
get_footer();
Can anyone help to point what I'm doing wrong here?
Here is defined codeigniter4 controller with form validation and view file. How can be reflected on view pages with errors.
Controller code is not reflected on view page . Could anyone clarify the issue of codeigniter4 validation.
Controller
public function register_user(){
helper(['form', 'url']);
$this->validation = \Config\Services::validation();
$validation = $this->validation;
$rules = [
'user_name' => [
'required' => 'All accounts must have usernames provided',
],
];
$this->validation->setRules([
'user_name' => 'required|min_length[2]',
],
$rules
);
if (! $this->validate($rules))
{
$validationErrors = $this->validation->getErrors();
return redirect()->back()->withInput()->with('errors', $validationErrors);
}
}
View
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login Registration</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" media="screen" title="no title">
</head>
<body>
<style type="text/css">
.error{color: red;}
</style>
<span style="background-color:red;">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Please do Registration here</h3>
</div>
<div class="panel-body">
<form role="form" method="post" action="<?php echo base_url('user/register_user'); ?>">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Please enter Name" name="user_name" type="text" autofocus>
<span class="error"><?php echo $validation->getError('user_name'); ?></span>
</div>
<input class="btn btn-lg btn-success btn-block" type="submit" value="Register" name="register" >
</fieldset>
</form>
<center><b>You have Already registered ?</b> <br></b> Please Login</center>
</div>
</div>
</div>
</div>
</div>
</span>
</body>
</html>
Following is the current result:
you can try this controller
public function register_user(){
helper('form');
if (! $this->validate([
'user_name' => 'required|min_length[3]|max_length[255]'
]))
{
echo view('user/login');
}
else{
echo view('user/login_view');
}
}
and this view:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login Registration</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" media="screen" title="no title">
</head>
<body>
<h2></h2>
<style type="text/css">
.error{color: red;}
</style>
<span style="background-color:red;">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Please do Registration here</h3>
</div>
<div class="panel-body">
<form role="form" method="post" action="<?php echo base_url('user/register_user'); ?>">
<fieldset>
<div class="form-group">
<?= esc($user_name); ?>
<span class="error"><?= \Config\Services::validation()->listErrors(); ?></span>
<input class="form-control" placeholder="Please enter Name" name="user_name" type="text" autofocus>
</div>
<input class="btn btn-lg btn-success btn-block" type="submit" value="Register" name="register" >
</fieldset>
</form>
<center><b>You have Already registered ?</b> <br></b> Please Login</center>
</div>
</div>
</div>
</div>
</div>
</span>
</body>
</html>
Dont forget to add route if this use:
$routes->add('/login', 'Login::login');
$routes->add('/user/register_user', 'User::register_user');
This post is not validated but the response of Wandi Tiger is ok for me.
With several rules you can do simply :
$validation = $this->validate([
'user_name' => 'required|min_length[10]|max_length[255]',
'user_pass' => 'required|min_length[10]|max_length[255]'
]);
if($validation)
{
echo view('user/login');
}
else{
echo view('user/login_view');
}
// Keep the old input values upon redirect so they can be used by the old() function
return redirect()->back()->withInput();
// Set a flash message
return redirect()->back()->with('foo', 'message');
You have combined both in your example which will not work
because the variable $validation which you are trying to access in view doesn't contain any data because you have not assigned any data to it
So you have to replace
if (! $this->validate($rules))
{
$validationErrors = $this->validation->getErrors();
return redirect()->back()->withInput()->with('errors', $validationErrors);
}
with this code:
if (! $this->validate($rules))
{
$data['validation'] = $this->validatior;
return view('view-name',$data); //note don't forget to replace view-name.
}
Don't change anything in the view file.
I am writing a small program in Vue.js, but I am getting stuck with an error.
I want the X button to remove each item in a list. I used splice(index,1), but the item isn't being removed. What am I missing?
My HTML:
<div id="app" class="container">
<div class="row">
<div class="col-md-4">
<h1>Add Student</h1>
<div class="form-group">
<label for="name">Name</label>
<input type="text" id="name" v-model="newStudent.name" class = "form-control" placeholder="Student Name">
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" id="address" v-model="newStudent.address" class = "form-control" placeholder="Address">
</div>
<button class="btn btn-success" v-on:click = "addStudent">Add</button>
</div>
<div class="col-md-8">
<h1>All Students</h1>
<table class="table table-striped">
<thead>
<tr>
<td>Name</td>
<td>Address</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr v-for = "student in students">
<td>{{student.name}}</td>
<td>{{student.address}}</td>
<td><button type="button" class="btn btn-danger" v-on:click="deleteStudent($index)">X</button></td>
</tr>
</tbody>
</table>
</div>
</div> <!--End of Row-->
<br>
<br>
<div class="row">
<div class="col-md-12">
<pre>{{ $data | json }}</pre>
</div>
</div>
</div>
My JS:
<script>
new Vue({
el: "#app",
data: {
newStudent: {name: "", address: ""},
students: []
},
methods: {
addStudent: function(){
var name = this.newStudent.name.trim();
var address = this.newStudent.address.trim();
if(name && address){
this.students.push({name: name, address: address});
this.newStudent = {name: "", address: ""};
$("#name").focus();
}
},
deleteStudent: function(index){
this.students.splice(index,1)
}
}
});
</script>
The $index variable was removed in Vue 2. So, you're not passing the index in correctly.
Specify the index variable in the v-for and pass that to the deleteStudent method instead:
<tr v-for="student, index in students">
<td>{{student.name}}</td>
<td>{{student.address}}</td>
<td>
<button
type="button"
class="btn btn-danger"
v-on:click="deleteStudent(index)"
>X</button>
</td>
</tr>
This is covered in the documentation on list rendering in Vue.
I am getting the details of product from the database. Here is my sample code I am unable to display images of the products! Can anyone help me out please?
The code to insert the product details in the database:
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title> Inserting product</title>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>
tinymce.init({ selector:'textarea' });
</script>
</head>
<body bgcolor="skyblue">
<form action="insert_product.php" method="post" enctype="multipart/form-data">
<table align="center" width="700" border="2" bgcolor="orange">
<tr align="center">
<td colspan="7"><h2>Insert New Post Here.</h2></td>
</tr>
<tr>
<td align="right"><b>Product Title:</b></td>
<td><input type="text" name="product_title" size="50" required /></td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" required>
<option>Select a categogory</option>
<?php
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while($row_cats=mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Brand:</b></td>
<td>
<select name="product_brand" required>
<option>Select a Brand</option>
<?php
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while($row_brands=mysqli_fetch_array($run_brands)){
$brand_id = $row_brands['brand_id'];
$brand_title = $row_brands['brand_title'];
echo "<option value='$brand_id'>$brand_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name="product_image" required/></td>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="text" name="product_price" size="50" required/></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols="20" rows="10"></textarea></td>
</tr>
<tr>
<td align="right"><b>Product Keywords</b></td>
<td><input type="text" name="product_keywords" size="50" required/></td>
</tr>
<tr align="center">
<td colspan="7"><b><input type="submit" name="insert_post" value="Insert Product Now"/></b></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
//getting the text data from the fields.
$product_title = $_POST ['product_title'];
$product_cat = $_POST ['product_cat'];
$product_brand = $_POST ['product_brand'];
$product_price = $_POST ['product_price'];
$product_desc = $_POST ['product_desc'];
$product_keywords = $_POST ['product_keywords'];
//getting the image data from the fields.
$product_image = $_FILES['product_image'][name];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
move_uploaded_file($product_image_tmp,"product_images/$product_image");
$insert_product = "insert into products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords) values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc',' $product_image','$product_keywords')";
$insert_pro = mysqli_query($con,$insert_product);
if($insert_pro) {
echo "<script>alert('Product has been inserted!')</script>";
echo "<script>window.open('insert_product.php','_self')</script>";
}
}
?>
The function part.
<?php
$con = mysqli_connect("localhost","root","","ecommerce");
//getting the categories
function getcats(){
global $con;
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while($row_cats=mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<li><a href='#'>$cat_title</a></li>";
}
}
//getting the Brands
function getBrands(){
global $con;
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while($row_brands=mysqli_fetch_array($run_brands)){
$brand_id = $row_brands['brand_id'];
$brand_title = $row_brands['brand_title'];
echo "<li><a href='#'>$brand_title</a></li>";
}
}
function getpro() {
global $con;
$get_pro = "select * from products order by RAND() LIMIT 1,6";
$run_pro = mysqli_query($con, $get_pro);
while($row_pro=mysqli_fetch_array($run_pro)){
$pro_id = $row_pro['product_id'];
$pro_cat = $row_pro['product_cat'];
$pro_brand = $row_pro['product_brand'];
$pro_title = $row_pro['product_title'];
$pro_price = $row_pro['product_price'];
$pro_image = $row_pro['product_image'];
echo "
<div id='single_product'>
<h3>$pro_title</h3>
<img src='\\ecommerce\admin_area\product_images\$pro_image' width='180' height='180' />
<p><b> $pro_price </b></p>
</div>
";
}
}
?>
**The web page to display all details**
<!DOCTYPE>
<?php
include("functions/functions.php");
?>
<html>
<head>
<title>Gal Baking Services LTD online Shop.</title>
<link rel="stylesheet" href="admin_area/product_images/style.css" media="all" />
</head>
<body>
<div class="main_Wrapper">
<div class="header_wrapper">
<img id="logo" src="images/ad bunner.jpg" />
<img id="bunner" src="images/ad bunner.jpg" />
</div>
<div class="menubar">
<ul id="menu">
<li>Home</li>
<li>All products</li>
<li>My account</li>
<li>Sign up</li>
<li>Shopping cart</li>
<li>Contact Us</li>
</ul>
<div id="form">
<form method="get" action="result.php" enctype="multipart/form-data">
<input type="text" name="user_query" placeholder="Search a product" />
<input type="submit" name="search" value="search" />
</form>
</div>
</div>
<div class="content_wrapper">
<div id="sidebar">
<div id="sidebar_title">Categories</div>
<ul id="carts">
<?php getcats();?>
</ul>
<div id="sidebar_title">Brands</div>
<ul id="carts">
<?php getBrands();?>
</ul>
</div>
</div>
<div id="content_area">
<div id="products_box">
<?php getpro(); ?>
</div>
</div>
</div>
<div id="footer">
<h2 style="text-align:center; padding-top:30px;">©2016 by www.krumblefresh.com </h2>
</div>
</div>
</body>
</html>
I would wish to thank everyone for your participation and for your support .
After straggling with my code on how to display images from mysql database,i came to realize that my code was perfect only that i had made some silly mistakes on the following lines of the insert_product.php file,
"$product_image = $_FILES['product_image'][name];".I failed to enclose the 'name' inside the single quotes ''.It should be,
$product_image = $_FILES['product_image']['name'];.
Also,on the following line
*
$insert_product = "insert into products
(product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords)
values
('$product_cat','$product_brand', '$product_title','$product_price','$product_desc',
' $product_image','$product_keywords')";
*, i had included a blank space inside the single quotes near $product_image.Its supposed to be ,
$insert_product = "insert into products
(product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords)
values
('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";
Thank you all.
I am working in a project with codeigniter and bootstrap, I made an autocomplete system, but the css looks broken like this
https://gyazo.com/4af7ae2bbdfd5547233d192b80ef947e
There is no custom style, only the bootstrap min css, here is my view html code, any help to look like it should be would be appreciated
<h2>Welcome to Crossover Laboratory</h2>
<div class="row">
<div class="col-md-1">
</div>
<div class='col-md-10 text-center'>
<h3>Patients</h3>
<?php echo $error2; ?>
<?php
$attributes2 = array(
"class"=>"form-horizontal",
"id" => "LoginForm2",
"name" => "LoginForm2",
"method" => "post"
);
echo form_open("laboratory/patients", $attributes2); ?>
<div class="form-group">
<input type="text" name="username_patients" id="username_patients" class="ui-autocomplete-input" value="" required placeholder="Name" />
<p id="patient_name"></p>
</div>
<div class="form-group">
<input type="password" name="password_patients" id="password_patients" value="" required placeholder="Code"/>
</div>
<div class="form-group">
<?php echo form_submit("Login2","Login"); ?>
</div>
<?php echo form_close(); ?>
</div>
<div class="col-md-1">
</div>
</div>
<script type="text/javascript">
$(document).ready(function($) {
$("#username_patients").autocomplete({
source: '<?php echo site_url('laboratory/autocomplete'); ?>',
minlenght: 2,
html: true,
open: function(event, ui)
{
$(".ui-autocomplete").css("z-index",1000);
}
});
});
</script>
I think you have missed the jQueryUI CSS references. Add the below CSS in your application <head> section and try..
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">