CodeIgniter Forums
Retaining dynamically added input boxes after form submit - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Retaining dynamically added input boxes after form submit (/showthread.php?tid=58831)

Pages: 1 2


Retaining dynamically added input boxes after form submit - El Forum - 07-24-2013

[eluser]squidol[/eluser]
I have a button (add another input) which appends new text box. I have already set validation rules for each dynamically generated input. The question is, how can i retain the dynamically added input boxes after form submit.

After i click submit, the view show only 1 input set (name, pull-ins, qualified) instead of 3 which was appended earlier before form submit.

pls see the images



Retaining dynamically added input boxes after form submit - El Forum - 07-24-2013

[eluser]PravinS[/eluser]
check set_value() function
http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html


Retaining dynamically added input boxes after form submit - El Forum - 07-24-2013

[eluser]squidol[/eluser]
sorry but you've misunderstood, i mean retaining the number of input fields not the POST data.

As you can see in the first screenshot i have appended 3 input sets because i clicked + Add interview button thrice. Then, after submitting the form i return to the same view with validation error because i did not fill in name3 field which has the rule "required" and some other fields. The problem is only 1 field is shown instead of 3.


Retaining dynamically added input boxes after form submit - El Forum - 07-24-2013

[eluser]noideawhattotypehere[/eluser]
You can use jquery
Code:
count = 0;
                    $("#divname input").each(function (){
                        count++;
                    });
will count all input fields from div id="divname", then just pass it as parameter while generating new page or whatever you want to do


Retaining dynamically added input boxes after form submit - El Forum - 07-25-2013

[eluser]SmokeyJoe[/eluser]
maybe you should submit your form via ajax. so your inputs don't get lost.


Retaining dynamically added input boxes after form submit - El Forum - 07-25-2013

[eluser]squidol[/eluser]
will i be able to use ci's form helper if forms are submitted using ajax?


Retaining dynamically added input boxes after form submit - El Forum - 07-25-2013

[eluser]SmokeyJoe[/eluser]
form helper or form validation helper?

to display the errors take a look at
http://darrenonthe.net/2011/05/10/get-codeigniter-form-validation-errors-as-an-array/

to add an input you can use jquery clone() and append()

to submit your data check $.post() or $.getJSON or $.ajax() and serialize()


Retaining dynamically added input boxes after form submit - El Forum - 07-25-2013

[eluser]veritascs[/eluser]
Just pass the form data to your view yea, and loop through adding the form fields as necessary?


Retaining dynamically added input boxes after form submit - El Forum - 10-21-2013

[eluser]Unknown[/eluser]
I have the same problem , do you find a solution on this ? thanks


Retaining dynamically added input boxes after form submit - El Forum - 10-21-2013

[eluser]35mm[/eluser]
If you use jquery ajax to submit the form, the form will remain as it was after it's submitted, complete with fields and input You can return the errors within the form, or use window location to send them somewhere if the submission is successful if you like. It's pretty easy to do. Google "submit a form with jquery ajax" and you should find lots of info, examples, code and tutorials.