0

I've been having a lot of troubles with this for the past few hours right now and I'm really not seeing where the problem is. Every single code snippet I find on the Internet is telling me I'm doing it right, but for some reason, nothing is working.

Basically, I have a form that requires fields to be dynamically added depending on the number of fields needed. My javascript to do this works fine:

    function ajouterStagiaires()
    {
    var innerHTML = new String();
    innerHTML = document.getElementById('stagiaires').innerHTML;
    var nombreStagiaires = document.getElementById('nbStagiairesConnus').value;

    innerHTML += "<tr><td><b>Nom </b></td><td><b>Matricule</b> </td></tr>";
    for(var i=0;i<nombreStagiaires;i++)
    {
        innerHTML += "<tr><td><input type='text' name='noms[]' /></td><td><input type='text' name='matricules[]' /></td></tr>";
    }
    document.getElementById('stagiaires').innerHTML = innerHTML;
    document.getElementById('nbStagiairesConnus').value = nombreStagiaires;

}

The fields are added properly in the page, but when I go to my PHP code, the $_POSTs done on noms and matricules are not being "detected" (yes, I have things entered in my fields in the web page).

if (isset($_POST['matricules']))
{
  echo "foo";
}

The "foo" is never printed. I have troubleshooted most of the common mistakes: my fields being added ARE in the form (CodeIgniter's echo form_open_multipart('foobar');). Every other field inside the form works perfectly fine.

The only thing I can see is that CodeIgniter is having problems with the JavaScript or something of the kind (though I don't know WHY it would have problems with it...) but other than that, I am completely stumped.

Thanks in advance.

2 Answers 2

1

In your javascript, where you are adding your input fields, put in a value = '' as well.

innerHTML += ... "input type='text' name='noms[]' value='' ..

In your CI controller, try this instead:

$matricules[] = $this->input->post("matricules");

if(is_array($matricules)) print_r($matricules);

This should pretty print the array of values passed from the form.

cheers,

Sign up to request clarification or add additional context in comments.

Comments

0

use FireBug to check the sourcecode and verify whether the fields are actually added where you want them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.