Part of the EllisLab Network
   
1 of 3
1
No $_POST data
Posted: 04 June 2009 07:47 PM   [ Ignore ]  
Summer Student
Total Posts:  5
Joined  03-30-2009

New to codeigniter, actually have to use it for this project.

Ok, I’m working with a situation where there will be dynamic number of input fields in a form so i need to use $_POST to iterate thru them

//Set post arg to vars
foreach ($_POST as $name=>$values{
    $this
->global_class->checkArgFiltered($name);
    echo 
"{$name} = {$value}";            

my form action is

<form action="<?php $_SERVER['SERVER_NAME'];?>/index.php/pdf/write" method="POST" enctype="text/plain"

I need $_POST to work or I need a codeignter method.

i tried calling $this->input->post() with out param hoping that it would return an array of the post args

Please help!

Profile
 
 
Posted: 04 June 2009 08:27 PM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2774
Joined  07-27-2006

So just iterate over $_POST like in your first example. What’s wrong with that?

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

Profile
 
 
Posted: 04 June 2009 08:36 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  5
Joined  03-30-2009

it’s empty, non of the post args are getting thru codeigniter

this is codeigniter blocking this because I have other project running on this server that are not CI

Profile
 
 
Posted: 04 June 2009 08:36 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  865
Joined  09-25-2007

to itterate what Colin has said.. here is an example test controller (which I have tested):

<?php
class Test extends Controller {

  
function Test() 
  
{
    parent
::Controller();
  
}
  
function index()
  
{
    
// should load a view but for demonstration purposes
    
echo ("<FORM action='".site_url()."/test/res' method='post'>
           <INPUT type='TEXT' name='testp'><input type='submit'></FORM>"
);
  
}
  
function res()
  
{
    print_r
($_POST);
  
}
}
?> 

result after submitting form

Array ( [testp] => datatypedin 
Profile
 
 
Posted: 04 June 2009 08:39 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  5
Joined  03-30-2009

let me re-iterate wink $_POST is empty

Profile
 
 
Posted: 04 June 2009 08:42 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  865
Joined  09-25-2007

have you tried cut and pasting my example?
it works here.

Profile
 
 
Posted: 04 June 2009 08:44 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  683
Joined  03-21-2009

And if you want the added security of the input class, do this:

foreach($_POST as $key => $value)
{
     $post_array[$key] 
$this->input->post($key);

     
//optional 2nd parameter of post() method runs xss filter if set to TRUE
     // e.g. $this->input->post($key, TRUE);

P.S. “Having” to use CodeIgniter is not a punishment, it’s a privilege wink

Profile
 
 
Posted: 04 June 2009 08:45 PM   [ Ignore ]   [ # 7 ]  
Lab Technician
RankRankRankRank
Total Posts:  1264
Joined  04-19-2008
BenInBlack - 05 June 2009 12:39 AM

let me re-iterate wink $_POST is empty

Then there must be another problem with your code. You probably need to show more code.

 Signature 

PinoyTech - Web Development Blog

Profile
 
 
Posted: 04 June 2009 08:58 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  5
Joined  03-30-2009

first off, thanks for the responses.


Controller

class Pdf extends Controller {

    
function Pdf()
    
{
        parent
::Controller();    
    
}
    
    
//the index function is what is called first on instantiation
    
function index()
    
{
    }
    
    
function read() {
        $this
->load->library('global_class');
        
$this->load->database();
        
$this->load->view('pdf_read');
    
}
    
    
function write() {
        $this
->load->library('global_class');
        
$this->load->database();
        
$this->load->view('pdf_write');
    
}

    
function form() {
        $this
->load->library('global_class');
        
$this->load->database();
        
$this->load->view('pdf_form');
    
}
    
    


pdf_form.php produces a basic form (for now)

<form action="/index.php/pdf/write" method="POST" enctype="text/plain">
<
input type="hidden" name="filename" value="base_form_4"/>  
<
hr>78 - (Text1) - Tx  - (test1)<br>Text1: <input type="text" name="Text1" value="test1"><br><hr>81 - (CheckBox1) - Btn  Yes<br>CheckBox1: <input type="checkbox" name="CheckBox1" value="Yes" checkedYes<br><hr>83 - (RadioButton1) - Btn  Yes<br>RadioButton1: <input type="radio" name="RadioButton1" value="Yes" checkedYes<br><hr>84 - (RadioButton1) - Btn  Yes<br>RadioButton1: <input type="radio" name="RadioButton1" value="No"No<br><hr>85 - (ComboBox1) - Ch [[(1)(item 1)][(2)(item 2)]] 1,item 1|2,item 2 - (2)<br>ComboBox1: <select name="ComboBox1" size="1" >

<
option value="1">item 1</option>
<
option value="2" selected>item 2</option>
</
select>
<
br><hr>86 - (Button1) - Btn  - <br>Button1: <input type="checkbox" name="Button1" value="No"No<br><hr>87 - (Text2) - Tx  - (test6)<br>Text2: <input type="text" name="Text2" value="test6"><br><hr>88 - (ListBox1) - Ch [[(1)(List 1)][(2)(List 2)]] 1,List 1|2,List - (2)<br>ListBox1: <select name="ListBox1" size="5" >
<
option value="1">List 1</option>
<
option value="2" selected>List 2</option>

</
select>
<
br><hr>
<
input type="submit" name="submit" value="Post Values and Write new PDF"/>  
</
form

This form is to post to the write function which calls pdf_write.php

at the top of pdf_write.php is the code to iterate through the $_POST array

but it is empty

Profile
 
 
Posted: 04 June 2009 09:07 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
RankRankRankRank
Total Posts:  1264
Joined  04-19-2008

Can you ensure that you’re ‘POST’-ing to the correct location?

 Signature 

PinoyTech - Web Development Blog

Profile
 
 
Posted: 04 June 2009 09:29 PM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  5
Joined  03-30-2009

I went back to verify the posting thru Zend debug trace and in watching the vars I saw the $HTTP_RAW_POST_DATA was getting set, but $_POST was still empty, that prompted my memory, that this code be an encoding issue.
and sure enough it was.

I use zend to quick enter html so it created

<form action="/index.php/pdf/write" method="POST" enctype="text/plain"

note the enctype…

I changed it to:
ENCTYPE=“multipart/form-data”

and bamo, I get $_POST data.

Sorry for wasting your time, thx for the help

Profile
 
 
Posted: 04 June 2009 09:41 PM   [ Ignore ]   [ # 11 ]  
Lab Technician
RankRankRankRank
Total Posts:  1264
Joined  04-19-2008

You need not set the enctype unless you’re uploading.

 Signature 

PinoyTech - Web Development Blog

Profile
 
 
Posted: 02 July 2009 09:10 AM   [ Ignore ]   [ # 12 ]  
Grad Student
Avatar
Rank
Total Posts:  49
Joined  01-31-2008

I actually copied and pasted that Test controller, and I also am not receiving anything from the print_r($_POST) statement.  I’ve tried it on a couple of projects on my local dev, no luck.

Perhaps an Apache configuration issue, though it’s pretty standard setup (just virtual hosts configured and entries in the /etc/hosts file as needed)?

Cheers,
Brian

Profile
 
 
Posted: 02 July 2009 09:31 AM   [ Ignore ]   [ # 13 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3896
Joined  04-25-2008

I’m wondering if this might be related to the uri_protocol at all. Can you call on any of your controller methods (other than index) directly from the address bar?

It might also be worth validating your HTML.

 Signature 

Remember the 8 Ps: Perfect Planning and Prior Preparation Prevents Piss-Poor Performance.


Not sure where to start with your project? Need some inspiration? Check out my CodeIgniter Resources thread

Profile
 
 
Posted: 02 July 2009 01:27 PM   [ Ignore ]   [ # 14 ]  
Grad Student
Avatar
Rank
Total Posts:  49
Joined  01-31-2008

Yes, other functions can be accessed using direct urls from the address bar no problem…

It’s a pretty standard 1.7.1 installation, a previous 1.6 installation with the above controller works fine.  Could certainly be a config parameter.  Currently the uri protocol is:

$config[‘uri_protocol’]  = “REQUEST_URI”;

Tried AUTO and others and no effect, though I cannot think of what would be stripping out the POST values completely?

Profile
 
 
Posted: 02 July 2009 02:29 PM   [ Ignore ]   [ # 15 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3896
Joined  04-25-2008

I’d suggest going back to basics, and just creating a simple script outside of PHP which will allow you to submit a post value, and then read it back to you. I suspect this will work, in which case, the problem is CodeIgniter (which I doubt), or that your HTML is not valid. Have you tried getting this to work with different browsers?

 Signature 

Remember the 8 Ps: Perfect Planning and Prior Preparation Prevents Piss-Poor Performance.


Not sure where to start with your project? Need some inspiration? Check out my CodeIgniter Resources thread

Profile
 
 
   
1 of 3
1