2016-09-20 84 views
0

我想在單擊表單提交時執行colorbox和php插入功能。如何對單個提交輸入類型執行colorbox和提交操作?

這是我的形式:

<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函數[對於表單提交]:

<?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代碼只是插入數據完美,但插入語句後,我需要在colorbox上打開#inline_content分區。它不' t執行。如何在將表單數據插入到數據庫後打開colorbox。

回答

0

最後我實現我的need.Just調用java腳本功能後,表格數據將插入。

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

您需要爲此使用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 
     } 
    }); 
+0

我有同一頁上的php和colorbox代碼。那麼我怎樣才能將單獨的url傳遞給php腳本。 –

+0

所以你可以把PHP代碼放在不同的文件中。 – Eimsas

+0

我達到了我的需要......感謝您的支持。 –