CodeIgniter Forums

Full Version: [solved]$this->input->post() not working?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]brucebat[/eluser]
Hi all,

My post function I seem to remember was working yesterday but for some reason it does not appear to work now after doing work on my View (CSS etc).

pic—> http://i.imgur.com/lpOqB.jpg

This is the code here which finds the last row entered by user which is found in my controller.

The problem is that it is giving back an error messages saying that all the rows are required when it should only be up to whatever the user enters.

e.g. the user completes 4/20 rows and forgets to enter a name in the “event” field in row number 4 then it would say “Name field in row 4 is required”.

However now it is saying they are all required? :S
Code:
//counter starts at zero which matches the field names that start at zero
$completedeventrows=0;


//finds the last time field by the user which will be assumed as the last row.
                
                do                
                    {
                       //if time field has been unchanged then it is assumed user did not use it
                        if( $this->input->post('time'.$completedeventrows) == '00:00:00')
                        {
                            
                            break; //
                        }
                        
                        $test =$this->input->post('time'.$completedeventrows);
                        echo $test;
                       $this->input->post('time'.$completedeventrows);
                      
                       $completedeventrows++;
                    }
                while ($completedeventrows <= $totaleventsrows);
-I have checked spelling;
Code:
&lt;input name="time0" value="00:00:00" maxlength="8" size="6"&gt;

Spelling is fine and it matches up at other side.

-I have tried checking to see if another input field has been unchanged and it works.

-When I try echoing a assigning a test variable from the post and then echoing it as I have shown above it does not echo anything. This is really strange.

I have a suspicion that its my View heres the pastebin:

http://pastebin.com/iNiWnqib

I have made a workaround for it at the moment which is just checking the “event” field instead of time but why is that working and not the other.

El Forum

[eluser]brucebat[/eluser]
Fixed it:

Apparently if you have

form_label() outside of form_open()

It can break your form!

This was what was wrong:

Code:
//Title
                    echo '<legend style="margin-bottom:20px;"><h2 style="color:#F00820;">Patient Data</h2></legend>';
                    echo '<fieldset style="border: none">';
                    //Labels
                    echo '<div id="patientlabels" style="display:block; float:left">';
                    echo '<h3>';
                        echo form_label('Age<color style="color:#F00820;">*</color>', 'patient_age'), '<br/>';
                        echo form_label('Gender<color style="color:#F00820;">*</color>', 'patient_gender'), '<br/>';
                        echo form_label('Weight (kg)<color style="color:#F00820;">*</color>', 'patient_weight'), '<br/>';
                        echo form_label('Height (m)<color style="color:#F00820;">*</color>', 'patient_height'), '<br/>';echo    
                    echo '</h3>';
                    echo '</div>';

form_open('submit/validateform'); // <--------------------THIS Should be before labels!

El Forum

[eluser]Aken[/eluser]
The form_label() function only generates an HTML <label> tag, which can be placed anywhere on a page, even without a &lt;form&gt; tag all together. <label> tags are also no part of the values that are submitted through a form, so there's zero ways that it would break your $this->input->post() on its own.

Based on your view, I'd say it has something to do with how you're processing the form through Javascript. JS is expecting to find those labels inside the &lt;form&gt; element, when you are placing them outside. I didn't go through your code enough to find out for sure, but I'd hate for you to unintentionally mislead anyone with a "fix" that is actually unrelated.

El Forum

[eluser]brucebat[/eluser]
My javascript only generates textfields.

When I compared my version of the forms using notepad++ the only differences where that my old form which worked had no form_labels() in it and my new one did.

So I removed them and then repositioned them and it worked.