Saturday, May 30, 2015

Bootstrap Modal Dialog Example in PHP

This article is to show how to popup a dialog in Modal and post in PHP.
Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web.  Bootstrap can be downloaded from:
Two files for this demo:
 modal_dialog.php, mydialogexample.js
<!DOCTYPE html>
<html lang="en">
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
  <script src="mydialogexample.js"></script>
<div class="container">
  <h2>Modal Dialog Example</h2>
  <!-- Universal Modal -->
 <h4>Student Number: <input type="text" name="student_number">
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" id="searchBtn_studentNum">Search Student</button> </h4>
<div class="modal fade" id="universalModal" tabindex="-1" role="dialog" aria-labelledby="universalModalLabel" aria-hidden="true">
  <div class="modal-dialog" style="width:1000px;">                                     
    <div class="modal-content">
      <form role="form" id="universalModalForm">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"> Close</span></button>
          <h4 class="modal-title"><span class="glyphicon glyphicon-pencil"></span> Edit<span class="modal-title">.model-title</span></h4>
        <div class="alert alert-danger fade in" id="universalModal-alert" style="display: none;">
          <span class="alert-body"></span>
        <div class="modal-body">.modal-body</div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary" id="submitBtn"></button>
<!-- Result Modal-->
<textarea id="searchResultForm" style="display:none">
  <table class="table table-striped table-hover" >
            <td><b>Last Name: </b></td>
            <td> <input type="text" name="lname">

            <td><b>First Name:</b> </td>
            <td> <input type="text" name="fname"></td>
        </tr>   </tr>
  <!-- Trigger the modal with a button -->


    $('#universalModal form').submit(function (event){

        var formObj = {};
        var inputs = $(this).serializeArray();
        var url = '';
        $.each(inputs, function(i, input) {
            formObj[] = input.value;
        var len = inputs.length;
        var  dataObj = {};
        for (i=0; i<len; i++) {
                 dataObj[inputs[i].name] = inputs[i].value;
                     $.post(url, inputs, function(data) {
        var student_num = $('input[name="student_number"]').val();
        $('#universalModal .modal-title').html('<b>Enter Student Info</b>');
        $('#universalModal .modal-body').html($('#searchResultForm').val());
        $('#universalModal .modal-footer button#submitBtn').html('Save and Exit');

Video:Bootstrap Modal Dialog Example in PHP

No comments:

Post a Comment