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

[eluser]mihaibaboi[/eluser]
Ok, so I got home and tried to replicate what you have. In order to make it easier for me, I used jQuery to add the dynamic field. But other than that, I hope I have the same setup as you do.

So, my "dinamic_form.php" view looks like this:


Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;Welcome to CodeIgniter&lt;/title&gt;
    [removed][removed]
&lt;/head&gt;
&lt;body&gt;

&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
        $("#addGender").click(function() {
            $("#genderRow").html("<p><label for=\"gender\">Gender</label>&lt;input type=\"text\" name=\"gender\" id=\"gender\" /&gt;&lt;/p>");
        });
        $("#addAge").click(function() {
            $("#ageRow").html("<p><label for=\"age\">Age</label>&lt;input type=\"text\" name=\"age\" id=\"age\" /&gt;&lt;/p>");
        });
    });
&lt;/script&gt;

<h1>Welcome to CodeIgniter!</h1>

&lt;?php

$firstName = array(
    "name" => "first_name",
    "id" => "first_name"
);

$lastName = array(
    "name" => "last_name",
    "id" => "last_name"
);

?&gt;


&lt;?php echo form_open("forms/submit"); ?&gt;
    <p>&lt;?php echo form_label("First Name", "first_name"); echo form_input($firstName); ?&gt;</p>
    <p>&lt;?php echo form_label("Last Name", "last_name"); echo form_input($lastName); ?&gt;</p>
    <p id="genderRow"><a id="addGender">Add gender</a></p>
    <p id="ageRow"><a id="addAge">Add age</a></p>
    <p>&lt;?php echo form_submit("submit", "Send"); ?&gt;</p>
&lt;?php echo form_close(); ?&gt;

&lt;/body&gt;
&lt;/html&gt;

As you can see, I have a form that submits to the "forms" controller (witch is the same that I'm calling for display) only I use the submit() method instead of index(). Also there are two placeholders before the submit button that will hold the dynamic fields. When I click each link, I use JavaScript to replace the link with a field.

The "forms.php" controller is dead simple. It looks like this:

Code:
class Forms extends CI_Controller {

    public function index()
    {
        $this->load->helper("form");
        $this->load->view('dinamic_form');
    }
    
    public function submit()
    {
        echo"<pre>";
        print_r($_POST);
        exit;
    }
}
So, I load the dynamic fields, fill them and hit Send. And the result looks like this:

Code:
Array
(
    [first_name] => Mihai
    [last_name] => Baboi
    [submit] => Trimite
    [gender] => Male
    [age] => 24
)

As you can see, I have access to all the fields in the form, so I don't think it's a CodeIgniter issue.

The code I provided is complete, so feel free to use it and compare to what you have. On the other hand, there maybe something else I'm missing. Is there something your doing that I didn't catch? Or is this what you wanted to achieve?
#12

[eluser]ximbo_fett[/eluser]
The only difference is that I wasn't using jQuery. I was just using DOM to try this. Let me give this a shot...
#13

[eluser]ximbo_fett[/eluser]
Thanks mihaibaboi,

Here's a stupid question for you about jQuery. How are you calling jQuery into your script? I haven't had much exposure to jQuery and I'm getting errors from your code. Do you have jQuery set in your autoload.php?


Thanks for your help!
#14

[eluser]louisl[/eluser]
You can just call it in the header of your page from a cdn or have it local.
<foo src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></foo>

replace foo with script and you're good to go.

http://docs.jquery.com/Downloading_jQuery

@ mihaibaboi not sure why you're doing all those escape chars, I find it best to use single quotes with strings for html type things ;-)
Code:
$('#genderRow').html('<p><label for="gender">Gender</label>&lt;input type="text" name="gender" id="gender" /&gt;&lt;/p>');
#15

[eluser]mihaibaboi[/eluser]
[quote author="ximbo_fett" date="1301965375"]How are you calling jQuery into your script?[/quote]

jQuery is inclded using the script tag at the beginning of the view (just like louisl said). As for the instance of jQuery, it's made automatically when you call jQuery specific code (like the $(element) selector).

You can have la look at the jQuery docs if you want to get started (they'r pretty comprehensive).

@louisl

I don't really like single quotes (I know, it's crazy). And your'e right, I should have used them here, at least to make the code easier to read Smile
#16

[eluser]ximbo_fett[/eluser]
Just wanted to let you all know that I figured out what was going on.

Apparently CI has issues where the form open tag is placed. After getting dynamic content to submit and display correctly outside of CI, I got it to work on an unbranded page inside CI. I then started disabling each page element until it worked...

The culprit??? I had the form open tag in inadvertently situated outside of the table in between rows. While this may not be proper, it works outside of CI. Inside CI however... disaster...

Just wanted to thank everyone for their help with this!
I have my form doing what it should be doing...

:-)
#17

[eluser]mihaibaboi[/eluser]
It makes sense not to work in CI, but I'm kind of puzzled why it would work anywhere else. An unproperly nested form tag will be thrown somewhere in the document flow (id the nesting involves tables). What I'm trying to say is that it shouldn't have worked anyway. Are you sure that the non CI code was replicating exactly what you had in CI?
#18

[eluser]ximbo_fett[/eluser]
It was replicated exactly outside as was inside CI. The form should, in theory, never have worked to begin with because of exactly what you said. The tag placement was an oversight on my part. Once I saw it, I knew it was exactly what was causing the problem...
#19

[eluser]mihaibaboi[/eluser]
Strange, but no matter. The important thing is that it works now, and your code is up and running Smile

I think I'll look into this issue one afternoon when I have some time to kill.
#20

[eluser]mihaibaboi[/eluser]
Just out of curiosity. Could you post the HTML that you were testing on? You can remove the JavaScript and stuff. I'm just interested to see the way the form was nested in the table, so that I can play around with it. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB