TDsouza
TDsouza

Reputation: 938

multiple ckeditor with same name textarea

I have a form that's created in a loop via php

it's something like this

<?php 

        $number = count($name_array);
        $id = 0;

        while($id<$number)
            {
                if($category[$id] == ewbp)
            {
            $ewbp = 'selected';
            }
                if($category[$id] == iwbp)
            {
            $iwbp = 'selected';
            }
                if($category[$id] == wbe)
            {
            $wbe = 'selected';
            }
                if($category[$id] == texture)
            {
            $texture = 'selected';
            }
                if($category[$id] == putties)
            {
            $putties = 'selected';
            }
                if($category[$id] == primer)
            {
            $primer = 'selected';
            }

        echo "
        <div class=\"update_form_holder\">
        <form action=\"processor/update.php\" enctype=\"multipart/form-data\" method=\"post\">
            <table>
                <tr>
                    <td>Name</td><td><textarea rows=\"1\" cols=\"30\" name=\"name\">"."$name_array[$id]"."</textarea></td>
                </tr>
                <tr>
                    <td>Small Description</td><td><textarea rows=\"2\" cols=\"60\" name=\"short_desription\">"."$short_description[$id] "."</textarea></td>
                </tr>
                <tr>
                    <td>Full Description</td><td><textarea rows=\"5\" cols=\"60\" name=\"long_description\">"."$long_description[$id]"."</textarea></td>
                </tr>
                <tr>
                    <td>Category</td>
                    <td>
                        <select name=\"category\">
                            <option value=\"ewbp\" ". "$ewbp" . ">Exterior Water Based Paints </option>
                            <option value=\"iwbp\" ". "$iwbp" . ">Interior Water Based Paints</option>
                            <option value=\"wbe\" ". "$wbe" . ">Water Based Enamel </option>
                            <option value=\"texture\" ". "$texture" . ">Textures</option>
                            <option value=\"putties\" ". "$putties" . ">Putties</option>
                            <option value=\"primer\" ". "$primer" . ">Premir</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td><input type=\"hidden\" value=\""."$idi[$id]"."\" name=\"idi\"></td>
                </tr>
                <tr>
                    <td><input type=\"submit\" value=\"update\"></td>
                </tr>
            </table>
        </form>
        </div>
        <div class=\"image_holder\">
            <img src=\""."$imgurl[$id]"."\" />
        </div>
        <form action=\"processor/delete.php\" method=\"post\">
            <input type=\"hidden\" value=\"$idi[$id]\" name=\"delete_id\">
            <input type=\"hidden\" value=\"$filename[$id]\" name=\"delete_file\">
            <input type=\"submit\" value=\"delete entry\" >
        </form>
        ";
        $id++;
        $ewbp = '';
        $iwbp = '';
        $wbe = '';
        $texture = '';
        $putties = '';
        $primer = '';
        }
        ?>

and im trying to get the textareas to use ckeditor, the problem is, it needs different names to create new instances, however I can't change the name as the data is submitted to another php file for storing in an sql database. Is there a way to get it to create more instances without having to change the name?? I tried using IDs but it didn't work. Moreover this link made me doubt whether it's even possible.

Upvotes: 1

Views: 4496

Answers (1)

hek2mgl
hek2mgl

Reputation: 157947

As you have control over the whole solution (php and html/javascript), the cleanest solution would be to choose a different name for each text area and change your php code so that those new names will be used when accessing the $_POST array.


Update: After having time for some tests, I cannot reproduce the problem. I've used the following html for testing - and it worked as expected, meaning that two ckeditors where rendered and can be submitted separately:

<html>
 <head>
    <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
 </head>
 <body>
    <form action="test.php" method="post">
      <textarea class="ckeditor" name="the_text"></textarea>
      <input type="submit">
    </form>

    <form action="test.php" method="post">
      <textarea class="ckeditor" name="the_text"></textarea>
      <input type="submit">
    </form>
 </body>
 </html>

I've used CKEditor version 4.1

Upvotes: 1

Related Questions