簡體   English   中英

如何對單個提交輸入類型執行顏色框和提交動作?

[英]How to perform both colorbox and submit action on single submit input type?

我想在單擊表單提交時同時執行colorbox和php insert功能。

這是我的表格:

 <form name="album" id="album"  action="#">
       <table>
           <tr>
               <td>Album Name</td>
               <td><input type="text" value="" name="album_titlee" required></td>
           </tr>
           <tr>
              <td colspan="2"><input class="button_new" type="submit" name="submit_album" id="submit_album"  value="ADD"></td>
           </tr>
      </table>
</form>

這是我的顏色框編碼

<div style='display:none'>
        <div id='inline_content' style='padding:10px; background:#fff;'>
            <p>We recommend the following resolutions for different print sizes.</p>
            <table>
                   <tbody>
                       <tr>
                          <th width="80" height="25">Size</th>
                          <th>Minimum Resolution</th>
                        </tr>
                        <tr>
                           <td height="25">3.5" x 5"</td>
                           <td>525 x 750 pixels (0.4 megapixels)</td>
                        </tr>
                   </tbody>
            </table>
        </div>
    </div>
</div>

這是我的php函數[For Form Submit]:

<?php
if(isset($_REQUEST['submit_album']))
{
$album_titlee=$_REQUEST['album_titlee'];
$user_id=$_SESSION['ses_userid'];


$sql=mysqli_query($conn,"INSERT INTO tbl_album(user_id,album_title,album_status) VALUES ('".$user_id."','$album_titlee','Y')");

echo("<script type='text/javascript'>$.colorbox({inline:true,width:'50%', href:'#inline_content'});</script>");

}
?>

上面的php代碼只是完美地插入了數據,但是在insert語句之后,我需要在colorbox上打開#inline_content分區。它不執行。在將表單數據插入db后,如何打開colorbox。

您需要為此使用ajax。 Javascript:

albumTitleeFromInput = $("input[name=album_titlee]").val();

$.ajax({
        url: "/urlToYourPhpScript",
        type: "POST",
        dataType: 'json',
        data: {
            album_titlee: albumTitleeFromInput
        },
        success: function (data) {
            //Open your colorbox in there
        }
    });

最終我達到了我的需要。只需在插入表單數據后調用Java腳本函數即可。

echo "<script type='text/javascript'>window.onload = function()
{
    popup();
}
</script>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM