Welcome Guest, Not a member yet? Register   Sign In
Form not including all fields...
#1

[eluser]ximbo_fett[/eluser]
Sorry if the solution is in another thread but I searched and couldn't find any solution.

I have created a form that uses Javascript createElement methods to dynamically create fields. I can use Javascript to validate these fields since I am assigning ids and names to them. I discovered that after the form is validated and submitted, these dynamically created fields are not making it to the processing function. All other fields are being POSTed to the controller, which is the same controller which is handling the form, but unless I create fields to drop these values in as they are being selected, the field values are never being submitted.

I am using form helper to create check-boxes but I am not using the form validation helper.

Is my issue using form helper? What do I need to do to get dynamically created fields to POST? I haven't had issues with this outside of codeigniters.

Thank you for any help...
#2

[eluser]ximbo_fett[/eluser]
Any ideas on this?

Does CodeIgniter block any fields that it doesn't generate as a prevention for XSS even if the XSS filter is off?

Should I post some code? Will it help?
#3

[eluser]ximbo_fett[/eluser]
I have removed the form helper and the form validation library from the controller and rewrote the view to not use CodeIgniter methods at all to create the form and the form elements. It still does not post the dynamically created form fields.

I created a page outside of the CodeIgniter framework and it posts these variables fine so I know that it isn't the Javascript, DOM, or the form doing this. Once I put this back into CodeIgniter, it doesn't post.

Is there anyone out there that can help me with this? Should I just implement an AJAX solution to post what was selected to the session as a work-around? The requirements for this project dictates that dynamically-created content be saved to a database so I need some sort of method to handle this inside the CodeIgniter framework.

Once again, thank you for any help...
#4

[eluser]stef25[/eluser]
Do you see the fields if you do a print_r($_POST) in the controller that handles form submission? If they are there, they should also be available to CI.

If not, then this is not a CI issue and probably quite tricky to fix.
#5

[eluser]ximbo_fett[/eluser]
If I put the code on a page outside of CI, it appears in the post when I do a print_r($_POST);. Look at the following print_r of the $_POST;

Array ( [title] => TEST [location] => TEST [description] => TEST [duration] => ends [duration_hours] => 2 [duration_minutes] => 5 [event] => one_time [event_hours] => 1 [event_minutes] => 0 [event_ante] => PM [event_month] => May [event_day] => 3 [event_year] => 2011 [sbmt] => Add Event )


When I put the same code inside of CI, the contents of a print_r($_POST); displays the fields that were written to the page when the page was rendered. This is the contents of the $_POST inside of CI with the same data as above submitted.

Array ( [title] => TEST [location] => TEST [description] => TEST [duration] => ends [event] => one_time [sbmt] => Add Event )

I can validate the contents of the dynamically created fields such as duration_hours or duration_minutes inside of CI but they are not passed when the form is submitted unlike the same page outside of CI.

This seems to me to be a CI issue since it works outside of CI. I agree that it is still quite tricky to fix since I am using the appropriate methods to create the fields.

Thanks once again for any help on this.
#6

[eluser]stef25[/eluser]
That's strang, not sure if / why CI would mess with the raw $_POST array. I'm sure something is being overlooked Smile You sure your form fields have proper name attributes?
#7

[eluser]ximbo_fett[/eluser]
Here is the input tag...

<select id="duration_hours" name="duration_hours" tabindex="5"><option value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> </select>


I pulled this straight out of the Firebug add-on. As you can see, it seems to be properly formatted HTML complete with id and name... :blank:
#8

[eluser]mihaibaboi[/eluser]
Just a thought... What are you using to redirect back to the view after the validation is done. Maybe you call the view in a way that does not run all the code that you expect it to. Maybe when you load the page the first time you use a trigger to create the dynamic fields, that doesn't fire when you redirect back.

It's just a guess, maybe you should look into it.
#9

[eluser]ximbo_fett[/eluser]
At this point I am not redirecting anything. I am trying to access POST information from the controller when the form is submitted - since a form should post whatever fields are embedded in it. There isn't any data sent from these dynamically created fields.

The fields are created by Javascript as an 'onChange' event. They are inside the form tags when they are created. I can validate the fields with Javascript and ensure that these choices are populated. When the form is submitted, the fields are not coming across and I cannot view them with print_r($_POST). If I put the script in a file outside of CI, the fields are submitted and I can view then with the print_r($_POST) command. This indicated to me that the form and Javascript work as intended and there is something in CI that is preventing the [duration_hours] => 2 [duration_minutes] => 5...
#10

[eluser]mihaibaboi[/eluser]
I'm sorry, I didn't understand the problem at first. Now I see what you mean. I'll have to try this tonight when I get home from the office and see what I can come up with.




Theme © iAndrew 2016 - Forum software by © MyBB