简体   繁体   中英

Ajax HTML FORM not sending input

i've got a problem I can't figure out.

I have a page (index.php) that open a form, includes another page with PHP (indexsearch.php) and close the form. This included page is working with a script that display some datas from my website, the data are requested on the page with an AJAX function that is linked to search.php, that is working with a table and checkboxes so we can choose which data to work with. See this schema :

在此处输入图片说明

Everything is working fine but the checkboxes are not send even when they are checked. I did added the name and the value in search.php

<td> <input type="checkbox" name="ajout[]" value="<?php echo $result['id']; ?>"/> </td>

I also did not opened another form. So I guess the problem may come from the fact the AJAX datas work as an independant form that is not included in my page.

Please see the html code :

<body>
<div class="division">
                    <table id="text-p">
                        <tr>
                            <td>
                        <form action="" method="get" enctype="multipart/form-data">
                            <textarea id="text-p1" name="text-p1" maxlength="300" placeholder="Text1"></textarea>
                            </td>
                            <td>
                            <textarea id="text-p2" name="text-p2" maxlength="300" placeholder="Text2"></textarea>
                            </td>
                        </tr>

                        <tr>
                            <td>
                            <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
                            Logo : <input name="logo-p1" type="file" accept="image/*">
                            </td>
                            <td>
                            <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
                            Logo : <input name="logo-p2" type="file" accept="image/*">
                            </td>
                        </tr>

              </table>
                </div>


                <div class="division">

        <div width="100%" style="height: 50px;">
            <input type="text" name="recherche" id="recherche" style="width: 75%; float:left; display: inline-block;" placeholder="Rechercher...">
            <div style="float:right;">
                    <input type="radio" name="onglet" value="val1" id="act" checked="">Activité
                    <input type="radio" name="onglet" value="val2" id="sect">Secteur
                    <input type="radio" name="onglet" value="val3" id="ecr">Ecrans
            </div>
        </div>
        <div width="100%" id="resultats">


                    <input id="ok" type="button" class="pageselector" name="pageselector" value="1" checked=""><table id="resultat1" width="100%" style="text-align: center;" class="resultatshow">
                <tbody><tr>
                        <td>Cat</td>
                                            <td>Text-1</td>
                        <td>Text-2</td>
                        <td>Sélec</td>

                </tr>
                        <tr>

                        <td>Cat1</td>
                                                <td>NULL</td>
                        <td>NULL</td>
                        <td> <input type="checkbox" name="ajout[]" value="1"> </td>
            </tr>

                    <tr>

                        <td>CAT2</td>
                                                <td>EMPTY</td>
                        <td>EMPTY</td>
                        <td> <input type="checkbox" name="ajout[]" value="2"> </td>
            </tr>

</table></div>                      
                    <input type="submit" value="UPDATE">

                </div>


            </body>

How can I fix that ?

I am not sure but I guess it can be caused by square brackets in the name attribute of your checkboxes. If you have reason to do it, you have to work with it properly. For example, here is the HTML form field:

<input type='checkbox' name='checkbox[myOption]'>

You have to remember that POST is an array of options. So doing like above you have to access it in the right way on the server side:

$_POST['checkbox']['myOption'];

I don't know if that solves your problem but I hope it helps a little bit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM