简体   繁体   中英

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

I want to perform both colorbox and php insert function on single click form submit.

This is my Form :

 <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>

This is my colorbox coding

<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>

This is my php function [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>");

}
?>

The above php code is only insert the data perfectly, but after insert statement i need to open #inline_content division on colorbox.It doesn't execute.How can i open the colorbox after insert form data into db.

You need to use ajax for that. 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
        }
    });

Finally i achieve my need.Just call the java script function after form data will insert.

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

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