Kohana 3.3 request->post() no data - php

I am having a problem with Kohana 3.3. I cannot get the $_POST values using $this->request->post() on my Controller. I dont know what I did wrong on my code. Hope you can help me out here. BTW, I was able to use Twig on all my templates using Kohana 3.3 but I wasn't able to process the data from my forms. Thank you. :-)
Here is my code:
Controller:
class Controller_Setup extends Controller{
public function action_item_group(){
if (HTTP_Request::POST == $this->request->method()){
// Post has no data
print_r($this->request->post());
}
$this->response->body( Twig::factory('setup/sample_form') );
}
}
View
<form class="form-horizontal" action="item_group" method="post" name="setup_form">
<input type="text" value="">
<button type="submit">Save</button>
</form>

You need to set name or id attributes to your HTML elements. Try this code and see if it's working now:
<form class="form-horizontal" action="item_group" method="post" name="setup_form">
<input name="group_name" type="text" value="">
<button type="submit">Save</button>
</form>

Related

Codeigniter : Pass data from view to controller using anchor tag

I am working on a project where I need to pass an ID to controller when someone clicks on the link, and open response in new tab.
I googled for solution on this, but couldn't find proper result. I also tried by sending data through URL in anchor tag, but then it gave an error of config.php file, so I reversed the code.
Currently I am using form tag to pass data. Can ye do this using PHP, or will we have to take help of jquery?
Here's View code:
<form class="form-horizontal" method="post" action='<?php echo base_url() . "home/edit_policy"; ?>'>
<div class="form-group">
<input type="hidden" class="form-control" id="polid" name="polid" value="<?php echo $ajax_view_pol_response[0]->polid; ?>">
<div class="col-sm-offset-3 col-sm-3">
<button class="btn btn-primary" id="editpolsubmit">Edit this Policy</button>
</div>
</div>
</font>
This code is from Controller:
public function edit_policy() {
$polid = $this->input->post('polid');
}
I want to transfer the "polid" from view to controller function using anchor tag.
All positive suggestions are appreciated.

Use form parameters in a route with Laravel 5

Imagine I have the following in my routes.php file:
Route::get('/test/{system}/{link}', function($system,$link)
{
return "test ok";
});
Then, I wanna access this route with a form from my view:
<form action="/" method="get">
<input type="text" name="system">
<input type="text" name="link">
<button type="submit">Go!</button>
<form>
What would be the best way to do that? I know I can do something like:
Route::get('/',function(){
$input = Request::only('link','system');
$url = 'test/'.$input['system'].'/'.$input['link'];
return redirect($url);
});
But I'm not sure if it's the correct way to achieve it.
Thanks in advance!
You could have js change the form action and then submit it. Your way is ok, but make sure to put it at the end of the routes file. I would actually have the form submit to some specific route (instead of / maybe /redirect-to or something) and from there redirect.
You can do this. I'm not sure if this is the best process.
In routes.php, do this:
Route::get('/form', function(){
return View::make('formview');
});
Route::get('/formaction', function(){
$link = Request::input('link');
$system = Request::input('system');
return "$link";
});
And in the view, as usual, the following:
<form method="get" action="formaction">
System: <input type="text" name="system" />
Link: <input type="text" name="link" />
<input type="submit" value="ok" />
</form>
The Request of Laravel does not depend on the verb used for the request.

codeigniter - form returning no data

I'm trying to create a page with a form using ci.
When i submit the form, the controller says that I have no data that's been submitted.
I can't see where my error lies.
Here's the view:
<?php echo validation_errors(); ?>
<?php echo form_open('widgets/search/'.$hardwaremodel.'/'.$objectid.'/'.$name.'/'.$fd); ?>
<div class="form-group">
<label for="search">Last 4 characters of address:</label>
<input type="text" class="form-control" id="searchstring" placeholder="last 4 characters" size="4">
</div>
<button type="submit" class="btn btn-default">Search</button>
<button type="cancel" class="btn btn-default">Cancel</button>
</form>
Once the page renders, the form tag ends up looking like this:
<form action="http://myserver/myciapp/index.php/widgets/search/205406zl/5461/SW-1/SW1net" method="post" accept-charset="utf-8">
The controller:
public function search()
{
$searchstring = $this->input->post(); // form data
var_dump($searchstring);
exit;
}
The results of the var_dump shows:
bool(false)
Thanks
EDIT 1
I haven't posted the entire HTML page that includes the form... but I display some of the fields passed in the URI as headings on the page - just before I create the form. Hope that clarifies...
Would this impact the POST data? Why is that relevant?
Thanks
A few things I'd suggest doing. First is, if you are going to include other variables in the form_open tag, I would add those variables to your controller, and put them in the form_open tag as URI strings. This will allow the form validation to work if you are going to echo out validation errors.
Also, you should be calling a name on the input->post() to get the specific item, (but you don't need to to get all POST data).
Controller:
public function search($hardwaremodel, $objectid, $name, $fd) {
$searchstring = $this->input->post('search_string'); // form data
var_dump($searchstring);
exit;
}
View:
<?php echo form_open('widgets/search/'.$this->uri->segment(3).'/'.$this->uri->segment(4).'/'.$this->uri->segment(5).'/'.$this->uri->segment(6)); ?>
<div class="form-group">
<label for="search">Last 4 characters of address:</label>
<input type="text" class="form-control" id="search string" name="search_string" placeholder="last 4 characters" size="4">
</div>
Form elements are referenced by name attribute which is missiong on input field searchstring.
Add:
name="searchstring"
on your input field.
in this code you have not used name attribute.You use id.
try this one
<input type="text" name="searchstring" value="xyz">

Form won't POST without Zend_Form

We (the entire team) have been pulling hair over this problem for the last 2 days. For some strange reason our Zend Framework 1.11.2 will not let us post plain form into the controller unless we create a Zend_Form class.
HTML in view file (no javascript, nothing):
<html><body>
<form action="/index/login/" method="post">
Email: <input type="text" name="email"/><br />
Password: <input type="password" name="password" />
<p><input type=submit name="ac" class="btn btn-success" value="Login"></p>
</form></body></html>
Index Controller:
public function loginAction()
{
$request = $this->getRequest();
if ($request->getParam('email')) {
Zend_Debug::dump($request);
}
}
$request->getParams() is empty!
But if we create a Zend_Form or pass the fields in as GET then $request->getParams() is filled with data.
I just don't get it. Is there something in Zend that you have to turn off to use plain form? We think we've tried everything, accessing global $_POST and $_REQUEST variables, and calling $request->getPost(). All empty unless we create a Zend_Form class and instantiate it inside the controller.
Looks like an problem with your Form Action. Please use "baseUrl" View Helper or URL View Helper to create correct action url:
<?php
// correct action url
$actionURL = $this->url(array(
'controller' => 'index',
'action' => 'login',
'module' => 'default',
));
?>
<html>
<body>
<form action="<?php echo $actionURL; ?>" method="post">
Email: <input type="text" name="email"/><br />
Password: <input type="password" name="password" />
<p><input type=submit name="ac" class="btn btn-success" value="Login"></p>
</form>
</body>
...pass the fields in as GET then $request->getParams() is filled with data.
Since you are crafting a form post, you will need to use the getPost() method.
public function loginAction()
{
if ($email = $this->_request->getPost('email')) {
Zend_Debug::dump($email);
}
}
First use the latest version
Zend Framework 1.11.11
Then try this code inside loginAction
if($this->getRequest()->isPost())
{
print_r($this->_getAllParams());
}

how to post a form data to controller using GET method in codeigniter

my view:
<form action="<?=base_url()?>index.php/frontend/main_con/temp">
<input type="text" name="temp">
<input type="submit"/>
</form>
Controller:
function temp(){
echo $_GET['temp'];
}
i cant able to reach this function and i got an error
An Error Was Encountered
The URI you submitted has disallowed characters.
So, how to pass form data in controller using GET method?
thanx in advance.
View:
<form action="<?=site_url('controller_name/function_name);?>" method="get">
<input type="text" name="temp">
<input type="submit"/>
</form>
Controller
class controller_name extends CI_Controller{
function function_name(){
echo $this->input->get('temp');
}
}
parse_str($_SERVER['QUERY_STRING'],$_GET);
ONLY worked for me after I added the following line to applications/config/config.php:
$config['uri_protocol'] = "PATH_INFO";
To solve the error go to this line. I personally think, that this is a mistake by design, because black-listing symbols from URI would be much better then white-listing.
As for GET variables .. you would have to use <form method="get" action="/what/ever/">.
Can't you use $this->input->get('temp');

Categories