我需要从外部表单或变通方法获取表单获取值

时间:2013-07-12 12:20:09

标签: php forms

我知道一点点javascript,我猜测有一些方法可以做到这一点,但我的问题仍然存在于PHP,我想在PHP中解决它

我有一个主窗体,其中包含一个deleteAll按钮,我有其他多种形式的复选框 如何按下我的deleteAll按钮并选中复选框的名称(因为它们带有ID)并最终获取其名称并执行mysql删除

这是我的代码循环并生成一个表单,一个删除所有按钮 并循环遍历我的数据库只生成许多形式,如此

echo '<div class="span12"><form action="admin/tool/editvehicle.php" method="post">
<button id="deleteall" name="deleteall" class="btn btn-danger" type="submit" >Delete</button></form>
</div>';
//get the total number of vehicles active in the database to loop through them and displaying them to manage
$query = mysql_query("SELECT COUNT('auto_id') FROM `auto`");
$all = mysql_result($query, 0);  //store the value so we can run this loop accordingly
$i = 1;
$auto_id = 0; //auto id equal to zero as starting point, it will increase randomly to as many vehicles it will diplay
while ($i <= $all)  //ie run for every car
{
    $fields = 'auto_id, year, make, model, engine, sound_system,mileage, price, att1, att2, att3, att4, att5, att6, att7, att8, 
    att9, att10, att11, att12, att13, att14, att15, picture1, picture2, picture3, picture4, picture5, picture6, picture7, picture8, 
    picture9, picture10, picture11, picture12';
    //check where the auto id is greater then the previously one according to $auto_id which increments
    $data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `auto` WHERE `auto_id` > $auto_id"));
    $auto_id = $data['auto_id'];  //here is the magic, we set the auto id to the current one being spitted out so it follows through
    //now with all the $data retrieved from the database we can print car by car with its unique info and ids
    echo '<div id="displaycarwrap" class="span3 container">
    <input id="deletebox" type="checkbox" name="a">
    <a href"#"><img src="' . $data['picture1'] . '"></img></a>
    <form action="admin/tool/editvehicle.php" method="post">
        <ul>
            <li>
                <br><b>Price</b>: <input name="price" type="text" class="span2" value="' . $data['price'] . '">
            </li>
            <li>
                <button name="delete" class="btn btn-danger" type="submit" >Delete Vehicle</button>
            </li>
            <li>
                <button class="btn btn-primary" name="editpictures" type="submit" >Edit Pictures</button>
            </li>
            <li>
                <button type="submit" name="editauto" class="btn  btn-inverse" >Apply Changes</button>
            </li>
        </ul>
        <button class="btn btn-mini  show_hide icon-th-list" href="#" rel="#slidingDiv'. $i .'">View details</button>
        <div id="slidingDiv'. $i .'" class="toggleDiv" style="display: none;">
        <ul> <br />
            <li><b>Year</b>:<br /><input type="text" name="year" value="' . $data['year'] . '" class="span2"></li>
            <li><b>Make</b>: <br /><input type="text" name="make" value="' . $data['make'] . '" class="span2"></li>
            <li><b>Model</b>: <br /><input type="text" name="model" value="' . $data['model'] . '" class="span2"></li>
            <li><b>Mileage</b>: <br /><input type="text" name="mileage" value="' . $data['mileage'] . '" class="span2"></li>
            <li><b>Engine</b>:<br /> <input type="text" name="engine" value="' . $data['engine'] . '" class="span2"></li>
            <li><b>Stereo</b> <br /><input type="text" name="sound_system" value="' . $data['sound_system'] . '" class="span2"></li>
            <li><b>Attribute 1 </b> <input type="text" name="att1" value="' . $data['att1'] . '" class="span2"></li>
            <li><b>Attribute 2</b> <input type="text" name="att2" value="' . $data['att2'] . '" class="span2"></li>
            <li><b>Attribute 3</b> <input type="text" name="att3" value="' . $data['att3'] . '" class="span2"></li>
            <li><b>Attribute 4</b> <input type="text" name="att4" value="' . $data['att4'] . '" class="span2"></li>
            <li><b>Attribute 5</b> <input type="text" name="att5" "value="' . $data['att5'] . '" class="span2"></li>
            <li><b>Attribute 6</b> <input type="text" name="att6" value="' . $data['att6'] . '" class="span2"></li>
            <li><b>Attribute 7</b> <input type="text" name="att7" value="' . $data['att7'] . '" class="span2"></li>
            <li><b>Attribute 8</b> <input type="text" name="att8" value="' . $data['att8'] . '" class="span2"></li>
            <li><b>Attribute 9</b> <input type="text" name="att9" value="' . $data['att9'] . '" class="span2"></li>
            <li><b>Attribute 10</b> <input type="text" name="att10" value="' . $data['att10'] . '" class="span2"></li>
            <li><b>Attribute 11</b> <input type="text" name="att11" value="' . $data['att11'] . '" class="span2"></li>
            <li><b>Attribute 12</b> <input type="text" name="att12" value="' . $data['att12'] . '" class="span2"></li>
            <li><b>Attribute 13</b> <input type="text" name="att13" value="' . $data['att13'] . '" class="span2"></li>
            <li><b>Attribute 14</b> <input type="text" name="att14" value="' . $data['att14'] . '" class="span2"></li>
            <li><b>Attribute 15</b> <input type="text" name="att15" value="' . $data['att15'] . '" class="span2"></li>
            <li><input type="text" name="auto_id" value="' . $data['auto_id'] . '" class="span2" readonly><li>
        <ul>
        </div>
    </form>
    </div>';
    $i++; //used for the while loop
}

screenshot

1 个答案:

答案 0 :(得分:0)

你可以在循环中添加表单id到表单内部,并且可以调用jquery来获取复选框的值,如

    $("input[name='foo[]']:checked:enabled",'#myform');  

其中myform是您的表单ID  要么   对于所有选中的复选框,请尝试jquery:

   $("input[type='checkbox']:checked")