Code Ingiter POST data empty - codeigniter

I'm just have a trouble when POST a multipart form with codeigniter. The form is contain text field and 8 field of file upload. the problem is, the file is uploaded successfully with no error, but the field of text is empty in my controller.
I tried to print_r the POST data and get an empty array. But sometimes when I'm using google chrome, It's not got any problem.
Any solution?

<form name="form" action="some action page.php" method="post" enctype="multipart/form-data">
<input type="text" name="inputfieldvalue" value="Input Field">
<input type="file" name="uploadedfile" id="uploadedfile">
<input type="submit" value="Submit" >
</form>
// suppose your form is like this as above then to check textfield value
<?php echo $_POST['inputfieldvalue']; ?>
// pass the name attribute whatever you have given to $_POST[your name field value]. like this

Complete example should be working.
your form target action to function my_form in My_controller controller. Lest try input with name WTF
<form name="form" action="my_controller/my_form" method="post" enctype="multipart/form-data">
<input type="text" name="WTF" value="Input Field">
<input type="submit" value="Submit" >
</form>
your cotroller action in My_controller.php file (CI Controller folder) should look le this
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class My_controller extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index(){
/* do something for page my_controller if you want */
} // end of index
function my_form() { // = my_controller/my_form
$here_is_it = $this->input->post('WTF'); // call value of input with name WTF
/* test it */
print_r($here_is_it);
}
Extra, to make sure everything it's okay. You can Enable auto load feature in Codeigniter. follow this tutorial

I Just check it for a while and the problem is not in the php or my html form code. But the problem is in my php.ini config. By increase upload max file size fix the problem. I just confused before because the form sometime work well and sometimes give an empty value.
Thanks in advance

Related

my delete query is not working in laravel

I am trying delete database data in Laravel. but this is not working my way.
my view page is
{{url('/deleteReview/'.$Review->id)}}
my web is
Route::post('/deleteReview/{id}','adminController#deleteReview');
my controller delete function is
public function deleteReview($id){
$deleteReview = Review::find($id);
$deleteReview->delete();
return redirect('/manageReview');
}
Are you trying to delete the review by opening the page /deleteReview/<id> in your browser? If so, this would be a GET request, so change the route to a get route:
Route::get('/deleteReview/{id}','adminController#deleteReview');
Please note as per the comments that a GET request should never change data server side. If data is changed using a GET request then there is a risk that spiders or browser prefetch will delete the data.
The correct way to do this in Laravel is using a POST request and use Form Method Spoofing to simulate a DELETE request. Your route entry would then look like this:
Route::delete('/deleteReview/{id}','adminController#deleteReview');
And your form would look like this:
<form action="/deleteReview/{{ $Review->id }}" method="POST">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
At Controller you should first set Validation for ID that you have to Delete. Create your own customize request handler such as DeleteRequest.
Once you get ID at Controller then used this code
public function deleteReview(DeleteRequest $id){
DB::table('reviews')->where('id', $id)->delete();
return redirect('/manageReview');
}
I hope it will work.

How to make a pretty simple Codeigniter url route?

I've looked some websites have a simple route in their login/registration form. For instance, their form redirect to action="/function/method". Recenttly I want to implement that route in codeigniter (I use codeigniter 3), but my form still break. I don't know how to.
Below is my simple controller:
/*
* i.e Folder: Login
* i.e Controller name: Login
* i.e steps: login/login/verify
*/
class Login extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
// Load login view
}
public function verify()
{
// Processing data from login form
}
}
And the login form is:
<form action="<?php echo base_url('login/login/verify'); ?>" method="post" class="form-horizontal">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<button class="btn btn-login" type="submit">Sign in</button></p>
</form>
As we can see the action is redirect to base_url()/login/login/verify or if we print this will make http://localhost/domain/login/login/verify. I think it's seem too long. What I want to is to simplify that route, for instance, action="/login/verify". I try to make route $route['login/(:any)'] = "login/login/$1" and it's not working. A little trick maybe to rename login folder i.e user, so that will be user/login/verify. But it's not what I want to.
Any idea or direction?
The issue is a you're attempting to call a method that doesn't exit.
Remember that Codeigniter's URL Scheme is:
http://localhost/codeigniter_installation/controller/method/params/..../
From your question, you appear to be calling:
/login/login/verify
login - controller
login - method
verify - param
This would be listed as: function login($action = "verify") { do_stuff() } in your controller.
When you should just be calling: /login/verify

Codeigniter textarea (angular.js ck editor ) Post not posting large data in controller

I am working on codeigniter3.0 I have some issue in ck editor post data. when i try to post large text data and try to get in controller like $this->input->post('textHeader'); it is not working. while I try to get like $_POST['textHeader']; it is working. any limit of codeigniter large data post?
No i don't think there is any limit of codeigniter 3.0 for large data post.
Here is my form.
<?php echo form_open('welcome/post_large'); ?>
<textarea name="large"></textarea>
<input type="submit" name="mysubmit" value="Submit Post!" />
<?php echo form_close(); ?>
My controller named welcome and post_large method.
public function post_large()
{
echo $this->input->post('large');
}
This is working fine.

refresh page with joomla component

I have a simple form in my tmpl/default.php:
<form id='AddForm' action="<?php echo JRoute::_('index.php?option=com_mycomponent&task=addcam'); ?>" >
<p>
<label for="CamName">Name:
</label>
<input type="text" id="CamName" name="cam_name" />
</p>
<button type='submit' class='submit_cam' name='addcam' value='Add'>Add</button>
<button type='reset' class='cancel_changes' name='cancel_changes' value='Cancel'>Cancel</button>
</form>
In my controller.php file I'm trying to process the values:
function addcam()
{
$add_name=JRequest::getString('cam_name');
$model = &$this->getModel();
$model->AddWebcam($add_name); //send to model to add to DB
}
In my model I just return the result of the query. With this implementation I just get routed to an empty page. I'd like to have it refresh the current page. Typically you do this with action="" but in my case I need it to route to the function called addcam in the controller. Or is there a better way to do this?
A common technique in Joomla when directing to the task is to have that function do a full redirect to a view at the end. This prevents a page refresh from trying to resubmit the data and leads to a cleaner url for the client. To do this, try the following:
function addcam()
{
$add_name=JRequest::getString('cam_name');
$model = &$this->getModel();
$model->AddWebcam($add_name); //send to model to add to DB
JFactory::getApplication()->redirect(JRoute::_(index.php?option=com_mycomponent&view=whatever));
}
Obviously, update the JRoute bit to the url you actually need. You can also include a message if you would like (like "Saved!"): http://docs.joomla.org/JApplication::redirect/1.6

Codeigniter pass a id to controller from view

I am using codeigniter for this project. I hava a id value in which i pass from controller A to view A. This id value is echo between an anchor tag. When this anchor tag is clicked on, it redirects to another controller B with the id value and processed this id value within controller B. Is there any other way of doing this other than using the uri class? Want to keep the url clean.
I thought of a way of appending hidden input elements when I shift from controller A to view A to controller B, but i realised it can be very messy.
Any clean ways of doing this? Thanks in advance guys!
New to using Stackoverflow See if you could understand my layout:
METHOD 1
Use the URI Class except you have good reasons not to.
From CONTROLLER_A
$data["id"] = ("ID NUMBER");
$this->load->view("VIEW_A", $data);
ANCHOR IN VIEW A
link
IN CONTROLLER_B
$id = $this->uri->segment(3);
.
METHOD 2
USE FORM POST if you want to keep things hidden:
$data["id"] = ("ID NUMBER");
$this->load->view("VIEW A", $data);
ANCHOR IN VIEW A
<form name="myform" id="myform" action="<?php echo base_url() ?>/controllerB/controllerfunction/" method="post">
<input type="hidden" name="id" id="id" value="<?php echo $id ?>" />
<input type="submit" value="See more" />
</form>
You could also use javascript to submit the form here via link if you which:
See more
Tips:You could also use css to hide submit button in the form by setting opacity to 0;
If link is within the form, you could use javascript:this.submit();
OR JQUERY
See more
$('#link').click(function() {
$('#myform').submit();
});
IN CONTROLLERB
$id = $this->input->post("id");
Well hidden inputs will work, and there's may another workaround that once you redirected to the method and use your id value i.e. get data from database, redirect again to another controller method with the clean URL you need , hope this is helpful

Resources