1

I am experiencing problems trying to do a multitextarea on a form.

I've a PHP view that has various forms, all processed different but in the same file. They all works, I've tested and they works. In forms there are a + icon that let the user add more instances of a <textarea />. This + icon loads via AJAX a new textarea with the same name of the previous textarea (for example, name="example[]"). If I post this, it only gets the first item that is the one that wasn't previously loaded by jQuery. The problem is that the ones loaded dynamically are totally ignored and I don't know why.

My extract of my PHP view:

    <?php echo form_open("projects/view/".$projectid); ?> <!-- This generates a valid <form /> tag -->
        <table>
            <tr>
                <th><?php echo lang("label_conx");?></th>
                <td class="textarea-edit">
                    <textarea class="context" name="CONX[]"><?php echo set_value("CONX[]");?></textarea>
                </td>
                <td class="add"><a id="add-conx" href="#"><?php echo img("img/icons/plus.png");?></a></td>
            </tr>
...

My jQuery code that works fine because the content is displayed and I see in firebug that is the same as the html loaded textarea:

$("a#add-conx").click(function(){
    $("#ajax-loader").fadeIn('normal');

    $("textarea.context:last").after('<textarea class="context" name="CONX[]"></textarea>');

    $("#ajax-loader").fadeOut("normal");

    return false;
});

And when I send the form, I've a in my PHP controller print_r($_POST); and I only get:

Array
(
    [CONX] => Array
        (
            [0] => safdsddasfafsd
        )
    ...

If I put on the PHP view various textareas, this array increases as same of the number of textareas I've created on the HTML view file. I don't understand why this is not working.

When the page is load: enter image description here

After adding some content dynamically: enter image description here

This two images shows 4 instances of textarea with the name context[] (that has been changed to CONX[], but fails equal) that are in the view. The second image shows the loaded ones with jQuery and PHP only detected the first 4 that were on the HTML.

Anyone has some idea how I can solve this?

Thank you in advance!

7
  • What is the submit method ? a regular submit or an ajax submit ? Commented Mar 8, 2011 at 11:00
  • @Jerome: Its a regular submit but there is like 5 submit buttons for (with different names) in the same page. Commented Mar 8, 2011 at 11:02
  • could yu explain it in simple terms Commented Mar 8, 2011 at 11:05
  • I'm not hearing anything wrong ... is there any chance you could post a link to a full HTML extract for the form? Commented Mar 8, 2011 at 11:08
  • 1
    Weird question but is your form tag closed ? Commented Mar 8, 2011 at 11:10

2 Answers 2

2

I suspect this has something to do with the correctness of your html.

Reading your question and the fact that you use a regular submit the problem could be a missing 'form' end-tag for instance.

Browsers sometimes have weird Javascript behaviors when the html is not properly nested.

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

Comments

0

You should take a look at the .live() function of jquery.

http://api.jquery.com/live/

2 Comments

I don't see how that's related ... any chance you could fill in the blanks? :)
Same... jQuery click don't fails. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.