When clicked submit button the page redirects from (localhost/cms/public/posts/create) to (localhost/posts) and then error page shows up. Was trying to display the input text using Controller. Below is my code
web.php
Route::resource('/posts','PostsController');
PostController.php
public function create()
{
//
return view ('posts.create');
}
public function store(Request $request)
{
//
return $request->get('title');
}
views/posts/create.blade.php
<html>
<head>
<title></title>
</head>
<body>
<h1>Form</h1>
<form method="post" action="/posts">
<input type="text" name="title" placeholder="enter title">
<input type="submit" name="submit">
</form>
</body>
</html>
error page
Action should be the name of page ur are trying to show
Try <action ="PostController.php">
Related
I'm trying to display set of values(hashtags) which I get from DB to View through controller.
But I'm stuck at here in this controller. Not sure what function to use, view or With after getting DB values. What will be best option to use? and how to use it in view
here is my sample code of Controller class
<?php
namespace App\Http\Controllers;
use App\Models\Hashtag;
use Illuminate\Http\Request;
use App\Http\Requests\SearchHashtagRequest;
class BannedHashController extends Controller
{
public function index(){
if(request()->query('query_hashtag')){
$hashtags = HashTag::where('hashtag','LIKE',"%{request()->query('query_hashtag')}%");
//Stuck in here
}else{
}
return view('bannedhashtags.index');
}
}
Index.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Instagram Hashtags</title>
</head>
<body>
<h1>Check your Instagram hashtags</h1>
<form method="get" type="get" action="{{url('bannedhashtags')}}">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for..." name="query_hashtag">
<span class="input-group-btn">
<button class="btn btn-secondary" type="submit">Go!</button>
</span>
</form>
</body>
</html>
you can do it like below:
public function index(){
if(request()->query('query_hashtag')){
$hashtags = HashTag::where('hashtag','LIKE',"%{request()->query('query_hashtag')}%");
return view('bannedhashtags.index',['hashtags'=>$hastags]);
}
return view('bannedhashtags.index');
}
and in this case you need to check for $hastags variable in your html like below
#if(isset($hashtags))
your html code here if the hashtags variable is set
#endif
if what you are looking for is to filter the hashtags list it will be better to show the hashtags list (maybe using pagination if the list is too big) and then filter it by using ajax request.
I am trying to implement a file upload function.
I am trying to enter the title, description and upload a file and return this request.. to ensure it is working... however I'm getting the error '404 Not found'.
I am attempting to use a csrf token in my create.blade.php to produce a string of the data I am entering.. I am not sure what I am doing wrong as I thought my routes were right.
Can anyone help me? I appreciate it.
web.php
Route::namespace('Admin')->prefix('admin')->name('admin.')->group(function(){
Route::middleware('can:create_files')->group(function(){
Route::get('/files/create', 'DocumentController#create');
Route::post('/files', 'DocumentController#store');
});
create.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<form action="/files" method="POST" enctype="multipart/form-data">
{{csrf_field()}}
<input type="text" name="title" placeholder="Title">
<input type="text" name="description" placeholder="Description">
<input type="file" name="file">
<input type="submit" value="Submit">
</form>
</body>
</html>
DocumentController
public function create()
{
return view('admin.document.create');
}
public function store(Request $request)
{
return $request;
}
I am using Codeigniter in My website and it works very well in all browsers in windows or phones except in snapchat.
When I am trying to submit the form I get the message:
message undefined index 'clientname'
message undefined index 'clientmessage'
<form action="<?php echo base_url(); ?>R/H/212F32" method="POST">
<input type="text" name="clientname" placeholder="name">
<textarea rows="5" name="clientmessage" placeholder="message"></textarea>
<input type="submit" value="send" />
</form>
I tried using an extra button with javascript to popup message alert of clientname and clientmessage content but nothing happens so I guess that there is something that happening in snapchat browser ?
Edited :
Controller 'T' That display the form
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class T extends MY_Controller {
public function __construct(){
parent::__construct();
}
function _remap($param) {
$this->index($param);
}
public function index($param)
{
$data = array();
$this->load->view('Head');
$data['code'] = $param;
$this->load->view('NewForm' , $data);
$this->load->view('Foot');
}
}
Controller 'R' That recive the form submited
<?php
class R extends MY_Controller {
public function H($c){
$this->load->view('Head');
$text = $_POST['clientname'];
$message = $_POST['clientmessage'];
//$this->input->post wont work also
// $this->input->post('clientname');
// $this->input->post('clientmessage');
$this->load->view('Foot');
}
}
UPDATED 10/05/2019 :
I tried to do basic form submit like this :
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Snapchat issue !</title>
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<form action="./Test.php" method = "post">
First name:<br>
<input type="text" name="firstname" value="Turki">
<br>
Last name:<br>
<input type="text" name="lastname" value="Test123">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Test.php
<?php
var_dump($_POST);
?>
The result :
in Android:
array(2) { ["firstname"]=> string(5) "Turki" ["lastname"]=> string(7) "Test123" }
in IOS:
array(0) {}
same thing happen without codeigniter so I rolled it out , but I noticed the following :
1 - it work fine in Snapchat in Android , but the issue appear in IOS only
2- in IOS if the link was send using snapchat chat it will work fine too even in IOS , but if it was linked in Story the issue appear !!!!
How do we send php page attribute values to a php class method?. I want to get php attribute values into a php class method. following is the way i tried.
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<form id="test" method="post" action="testPhp.php">
<label>Name</label>
<input type="text" name="n1" id="name" />
<input type="submit" value="ADD NAME">
</form>
</body>
</html>
Now I want to get this name value in method in separate php file
testPhp.php
<?php
class getParam{
public function getFormParm(){
$name = $_POST['n1'];
}
}
?>
You have no valid action declared as the forms action. Try $_SERVER['self'] as the form action, like so:
<body>
<form id="test" method="post" action="<?php echo $_SERVER['self']?>">
<label>Name</label>
<input type="text" name="n1" id="name" />
<input type="submit" name='submit' value="ADD NAME">
</form>
</body>
And to get the result of this, do the following:
<?php
echo $_POST['n1'];
?>
The way you have the class set up, you aren't actually doing anything with the class. Nothing is being executed. You can do something like this:
<?php
class getParam{
public function getFormParm(){
$name = $_POST['n1'];
return $name;
}
}
// This is the part that you are missing
$getParam = new getParam();
echo $getParam->getFormParm();
i am tring to set cookie in codeigniter but i cannt make it happen i dont know what is wrong.
there is no error on the error log page...
this is my view page...
<!DOCTYPE html>
<html>
<head>
<title>
EKART
</title>
</head>
<body>
<h1>SIGN IN</h1>
<form id="admin" action="/do/ekart/adminlogin/login/" method="POST">
Name :<br/>
<input type="text" name="name" id="name"/><div id="name_display"></div><br/>
Password :<br/>
<input type="password" name="password" id="pasword"/><div id="password_display"></div><br/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
and here is my controller..
adminlogin.php
<?php
class adminlogin extends Controller{
public function __construct(){
parent::Controller();
$this->load->library('mylib');
}
public function index(){
$this->load->view("ekart/adminlogin");
}
public function login(){
$name=$_POST["name"];
$password=$_POST["password"];
$data=array("username"=>$name,"password"=>$password);
$result=$this->mylib->logincheck($data);
if($result){
echo "every thing is fine";
setcookie("myCookie",$name,time()+3600,"/");
$this->load->view("ekart/home",array("message"=>""));
}
}
}
the control is going inside if and it also prints "every thing is fine" the home page is also get loaded but i dont know why the cooke is still not set..
mylib is my library to check login validation....
There is a codeigniter way of doing this.
Make sure to have $this->load->helper('cookie'); in your controller, or autoload it.
$cookie = array(
"username" => $name,
"time" => time()+3600
);
$this->input->set_cookie($cookie);