Welcome Guest, Not a member yet? Register   Sign In
Retaining dynamically added input boxes after form submit
#1

[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
#2

[eluser]PravinS[/eluser]
check set_value() function
http://ellislab.com/codeigniter/user-gui...elper.html
#3

[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.
#4

[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
#5

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

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

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

to display the errors take a look at
http://darrenonthe.net/2011/05/10/get-co...-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()
#8

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

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB