Welcome Guest, Not a member yet? Register   Sign In
Adding a dynamic number of input boxes
#1

[eluser]borgir[/eluser]
Hey CI'ers!!
I need to make some view with a dynamic number of input boxes so that the users can submit several files with only one submit, using (the user) one button for adding one input box at a time.
What's the better solution to solve this problem (view and controller)? (just looking for tips, not asking for code =)).
Thks a lot!
#2

[eluser]imn.codeartist[/eluser]
i vote 100% to go with view
#3

[eluser]borgir[/eluser]
My question isn't if I should use view or controller since I'm gonna need both.
The question is how can I make the process dynamic. How can I make a button that generates input boxes (one at a time) and after that how can I send that info to my controller?
Thks!
#4

[eluser]mjsilva[/eluser]
Here is solution using Jquery:

In View:

Code:
<html>
    <head>
        <s.c.r.i.p.t. src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></s.c.r.i.p.t.>

        <s.c.r.i.p.t type="text/javascript">
        
        $("#more_one_input").click(function(){
            
            var html = "&lt;input type='text' name='my_dynamic_inputs[]' /&gt;";
            
            $("#my_dynamic_input_div").append(html);
            
        });
        </s.c.r.i.p.t.>
    &lt;/head&gt;
    &lt;body&gt;
        <a href="#" id="more_one_input">Add one input</a>
        &lt;?=form_open("my_form")?&gt;
        <div id="my_dynamic_input_div"></div>
        <p>&lt;?=form_submit()?&gt;</p>
        &lt;?=form_close()?&gt;
    &lt;/body&gt;
&lt;/html&gt;

In PHP:

Code:
&lt;?php

class my_form extends Controller {
    
    function index()
    {
        $my_inputs_array_values = $this->input->post("my_dynamic_inputs");
        
        foreach ($my_inputs_array_values as $key => $value )
        {
            echo $value;
        }
                
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}
?&gt;


Not tested, errors are expected!

Hope it helps
#5

[eluser]borgir[/eluser]
Man! Amazing... Thks a lot!
Silva.. are you from Portugal?
Cheers!
#6

[eluser]mjsilva[/eluser]
No prob, glad it helped.

Yes, I'm from Portugal Smile
#7

[eluser]borgir[/eluser]
Me too =)
Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB