Question

When I try and insert a form into a thickbox for use in the admin area, it seems to be removed completely. What do I need to change?

<?php
    // Enqueue thickbox js and css
    add_thickbox();
?>

<div style="text-align:center;padding:20px 0;"> 
<input alt="#TB_inline?width=500&height=600&inlineId=examplePopup1" title="Insert/edit link" class="thickbox" type="button" value="Tickbox 1" />  
</div>

<div id="examplePopup1" style="display: none">
    <div name="buffer">
        <form name="test" action="www.test.php" method="post">
            <input type="text" class="item-permalink" value="test">
            <input type="submit" value="Add Link" class="button button-primary" id="link_form-submit" name="link_form-submit">
        </form>
    </div>
</div>

In the browser I simply get

<div id="examplePopup1" style="display: none">
    <div name="buffer">
        <input type="text" class="item-permalink" value="test">
        <input type="submit" value="Add Link" class="button button-primary" id="link_form-submit" name="link_form-submit">
    </div>
</div>
Was it helpful?

Solution

The issue you are running into is partially an HTML issue. Forms cannot be nested. You are likely putting this inside of another form (as a great bulk of the backend is already forms).

WordPress provides good handling for receiving submitted data to extend core functionality. I suggest that you look into this and figure out how to capture the data from those fields when the form is submitted and do what you wish with it from there.

See: https://stackoverflow.com/questions/379610/can-you-nest-html-forms

OTHER TIPS

A bit late now but maybe it helps anyway. I solved it by adding the thickbox div to the 'admin_footer' via filter. If you do so the code is outside the general form.

Ok so here is the code how i added a form:

<?php 



add_filter('admin_footer-edit.php', 'expose_form');
function expose_form(){

  ?> 
    <div id="expo" style="display:none;" >
        <h3>Andruck wählen</h3>
        <div class="form">
            <table class="expformtable">
        <form action="" method="post" class="expgen">
             <input type="hidden" class="id" name="id" value="">
            <tr>
                <th>Andrucken</th>
                <th>Seite</th>
            </tr>
              <tr>
                <td><input type="checkbox" name="titlepage" value="titlepage" checked="true"></td>
                <td><label for="titlepage">Titelseite andrucken</label>
                    <ul>
                        <li><input type="checkbox" name="grayscale" value="grayscale"> Graustufenbilder</li>
                    </ul>

                </td>
            </tr> 
            <tr>
                <td><input type="checkbox" name="detailpage" value="detailpage" checked="true"></td>
                <td><label for="titlepage">Detialsseite andrucken</label>
                    <ul>
                        <li><input type="radio" name="adaptiveheight" value="adaptive" checked="true"> Adaptive Zeilenhöhe</li>
                        <li><input type="radio" name="adaptiveheight" value="fixed"> Fixe Zeilenhöhe</li>
                    </ul>


                </td>
            </tr>
            <tr>
                <td><input type="checkbox" name="mappage" value="mappage" checked="true"></td>
                <td><label for="titlepage">Karte andrucken</label></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="textpage" value="textpage" checked="true"></td>
                <td><label for="titlepage">Textseiten andrucken</label></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="picpage" value="picpage" checked="true"></td>
                <td><label for="titlepage">Bildseiten andrucken</label></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="agbpage" value="agbpage" checked="true"></td>
                <td><label for="titlepage">AGB Seite andrucken</label></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="docpage" value="docpage" checked="true"></td>
                <td><label for="titlepage">Mieterliste andrucken</label></td>
            </tr>
             <tr>
                <td><input type="text" name="imagequality" value="30"></td>
                <td><label for="imagequality">Bildqualität %</label><p>100 = Originalbilder 0 = kleinste Dateigröße</p></td>
            </tr>
             <tr>
                 <td colspan="2">  <input type="submit" class="button-primary" value="genereieren"></td>
            </tr>         
        </form>
            </table>
       </div> 
        <div class="ajaxloading">
            <div class="spinner"></div>
        </div>     
   </div>

  <?php     
}

It`s just a simple form added via admin_footer filter the -edit.php sufix ensures that its only added at the post pages.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top