I have a slew of dialogs and on 2 of them have forms where the user needs to submit information to be stored in the database without the page refreshing. Here is my code so far
index page
- <?php
-
- require('classes/change-of-address.php');
- require('classes/insert-comment.php');
-
- if(isset($_POST['change_of_address_form'])) {
- //submit change of address
- $coa = new ChangeOfAddress();
- $coa->SaveToDatabase();
- }
-
- else if(isset($_POST['comment_form'])) {
- //submit comment
- $c = new InsertComment();
- $c->SaveComment();
- }
- ?>
-
- <!DOCTYPE html>
- <head>
- <meta charset="utf-8">
- <title>BOS Editor</title>
- <meta name="description" content="">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" type="text/css" src="http://normalize-css.googlecode.com/svn/trunk/normalize.css" />
- <link rel="stylesheet" type="text/css" href="css/main.css" />
- <link rel="stylesheet" type="text/css" href="css/jquery-ui.min.css" />
- <link rel="stylesheet" type="text/css" href="css/jquery-ui.structure.min.css" />
- <link rel="stylesheet" type="text/css" href="css/jquery-ui.theme.min.css" />
- <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.css" />
- </head>
- <body>
-
-
- <form name="main_form" method="post">
-
- <div id="content">
- <div id="header"><img src="images/Search.png" alt="" /><h1>Search</h1>
- </div><!-- end #header div -->
-
- <div id="search-panel">
- <input type="text" id="search" name="search" size="10" />
- <select>
- <option value="Parcel">Parcel</option>
- <option value="Owner Name">Owner Name</option>
- <option value="Address">Address (Mailing, Property, City, State, or Zip)</option>
- <option value="AccountNumber">Account Number</option>
- <option value="NotesField">Other (Notes Field)</option>
- </select>
- <input type="button" id="Search" name="Search" class="darkButton" value="Search" />
- <input type="button" id="ShowColumnChooser" name="ShowColumnChooser" class="darkButton" value="Show Column Chooser" />
- <input type="button" id="Export" name="Export" class="darkButton" value="Export" />
- </div><!-- end #search-panel div -->
- <div id="column-chooser">
- <input class="noMargin" type="checkbox" id="InCareOf" /> In Care Of <input type="checkbox" id="SiteAddress" /> Site Address <input type="checkbox" id="SiteCityStateZip" /> Site City, State, Zip <input type="checkbox" id="Address" /> Address <input type="checkbox" id="CityStateZip" /> City, State, Zip <input type="checkbox" id="ResponseCode" /> Response Code <input type="checkbox" id="InitialMailDate" /> Initial Mail Date <input type="checkbox" id="ReclassMailDate" /> Reclass Mail Date
- </div><!-- end #columnchooser div -->
-
- <div id="search-results">
- <table id="dataTable" class="display">
- <thead>
- <tr>
- <th>Column 1</th>
- <th>Column 2</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>Row 1 Data 1</td>
- <td>Row 1 Data 2</td>
- </tr>
- <tr>
- <td>Row 2 Data 1</td>
- <td>Row 2 Data 2</td>
- </tr>
- </tbody>
- </table>
- </div><!-- end #search-results div -->
-
- <div id="edit-panel">
- <h3 class="floatLeft">Editing: php echo $parcel;</h3>
- <input type="button" name="ViewComments" id="ViewComments" class="greyButton floatLeft" value="View Comments" />
- <input type="button" name="ChangeOfAddress" id="ChangeOfAddress" class="greyButton" value="Change of Address" />
- <p>Appeal Address Match <input type="checkbox" /></p>
- <table>
- <tr>
- <td style="width:200px;">Date Appeal Received</td>
- <td style="width:200px;">BOS Meeting Date</td>
- <td style="width:200px;">Late Returns Date</td>
- <td style="width:200px;">Determination Notice Sent Date</td>
- </tr>
- <tr>
- <td><input type="text" id="datepicker1" name="datepicker"></td>
- <td><input type="text" id="datepicker2" name="datepicker"></td>
- <td><input type="text" id="datepicker3" name="datepicker"></td>
- <td><input type="text" id="datepicker4" name="datepicker"></td>
- </tr>
- <tr>
- <td>Final Determination</td>
- <td>Analysis / Recommendation</td>
- <td></td>
- <td></td>
- </tr>
- <tr>
- <td><select id="FinalDetermination" name="FinalDetermination">
- <option value="" style="width:20px;"> - Please Select - </option>
- <option value="None">None</option>
- <option value="A">A - Approve</option>
- <option value="D">D - Deny</option>
- <option value="H">H - Hold</option>
- </select>
- </td>
- <td><select id="AnalysisRecommendation" name="AnalysisRecommendation">
- <option value="" style="width:20px;"> - Please Select - </option>
- <option value="None">None</option>
- <option value="3">3 - Primary</option>
- <option value="4.1">4.1 - Non-Primary</option>
- <option value="4.2">4.2 - Rental</option>
- </select>
- </td>
- <td></td>
- <td></td>
- </tr>
- </table>
- <div class="floatLeft"><p>Email Address</p><input type="text" id="EmailAddress" name="EmailAddress" size="40" /></div>
- <div class="floatLeft"><p>Phone Number</p><input type="text" id="PhoneNumber" name="PhoneNumber" size="40" /></div>
- <div class="clearFloat"></div>
- </div><!-- end #edit-panel div -->
-
- <div id="footer">
- <ul>
- <li><a href=""><?php echo $username; ?></a></li>
- <li><a id="Help">Help</a></li>
- <li><a href="">Users</a></li>
- </ul>
- </div><!-- end #smoothmenu1 div --></div><!-- end #footer div -->
-
- <div id="CommentsDialog" title="Comments">
- <textarea readonly style="width:100%;height:85%; margin-bottom:5px;" id="Comment" name="Comment"></textarea>
- <input type="text" style="width:65%;margin-top:5px;" id="InsertComment" /> <input type="submit" id="AddComment" value="Add Comment" class="floatRight" />
- <input type="hidden" id="comment_form" name="comment_form" />
- </form>
- </div>
- <div id="ChangeAddressDialog" title="Change of Address">
- <p><input type="checkbox" style="width: auto;" id="ChangeRequested" name="ChangeRequested" /> Change of Address Requested</p>
- <p>Mailing Address: <input type="text" id="Address1" name="Address1" /></p>
- <p>Mailing Adress 2: <input type="text" id="Address2" name="Address2" /></p>
- <p>City: <input type="text" id="City" name="City" /></p>
- <p>State: <input type="text" id="State" name="State" maxlength="2" /></p>
- <p>Zip Code: <input type="text" id="Zip" id="Zip" /></p>
- <p>Country: <input type="text" id="County" name="Country" /></p>
- <input type="hidden" id="change_of_address_form" name="change_of_address_form" />
- </div>
- <div id="HelpDialog" title="Help">
- <p><strong>How do I search for items?</strong></p>
- <p>To search for items, enter in some text to search fro and select the type of search you would like to perform. You can include wildcard characters in your query("*" is a wildcard character). For example, to find all parcels starting with 101, you would enter in 101*. To final all parcels starting with 101 and ending with 900, you would enter in 101-*-800*. If you do not ad a "*" to your query, one will be added automatically.</p>
- <p><strong>Can I sort columns in my search results?</strong></p>
- <p>Yes. Click on a header and it will automatically sort ascending or descending.</p>
- <p><strong>How do I group search results?</strong></p>
- <p>To group your search results, drag a column header up to the grouping bar (where it says "Drag a column header here to group by that column"). You can add multiple columns to perform a cascading drill down.</p>
- <p><strong>How do I edit a record?</strong></p>
- <p>If you have editor rights, you can edit a record by scrolling down to the filed you want to edit in the bottom form. Once you have made your changes, click out of the field or hit enter to save them to the database. All changes are automatically done for you.</p>
- <p><strong>Can I print the search results or the current record I am editing?</strong></p>
- <p>This feature is coming soon! <img src="images/smiley.png" /></p>
- <p><strong>Can I export the search results or the current record I am editing to a spreadsheet (or other format)?</strong></p>
- <p>This feature is coming soon! <img src="images/smiley.png" /></p>
- </div>
- <div id="ExportDialog" title="Export Records">
- <ul>
- <li><a href="">Export Penalty Data</a></li>
- <li><a href="">Export A (Approved) Records</a></li>
- <li><a href="">Export D (Denied) Records</a></li>
- <li><a href="">Export H (Hold) Records</a></li>
- <li><a href="">Export Analysis Records</a></li>
- <li><a href="">Export Late Returns Records</a></li>
- </ul>
- </div>
- </form>
-
- </div><!-- end #content div -->
-
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
- <script type="text/javascript" src="js/jquery-ui.min.js"></script>
- <script type="text/javascript" charset="utf8" src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.js"></script>
- <script type="text/javascript" src="js/modernizr-2.6.2.min.js"></script>
- <script type="text/javascript" src="js/ddsmoothmenu.js"></script>
- <script type="text/javascript" src="js/form-attribute-polyfill.js"></script>
- <script>
- $(document).ready(function() {
- $('#column-chooser').hide();
- $('#CommentsDialog').hide();
- $('#ChangeAddressDialog').hide();
- $('#HelpDialog').hide();
- $('#ExportDialog').hide();
- });
- $('#dataTable').DataTable();
- $( "#AddComment" )
- .button()
- .click(function( event ) {
- event.preventDefault();
- });
- $('#ShowColumnChooser').click(function() {
- //show/hide div
- $('#column-chooser').slideToggle('slow');
- });
- $('#Help').click(function() {
- //help dialog box
- $( "#HelpDialog" ).dialog({
- width: 500,
- modal:true,
- closeOnEscape:true,
- buttons: [ { text: "Close", click: function() { $(this).dialog( "close" ); } } ]
- });
- });
- $('#Export').click(function() {
- //export options dialog
- $( "#ExportDialog" ).dialog({
- width: 500,
- modal:true,
- closeOnEscape:true,
- buttons: [ { text: "Close", click: function() { $(this).dialog( "close" ); } } ]
- });
- });
- $('#ViewComments').click(function() {
- //view/add comments dialog
- $( "#CommentsDialog" ).dialog({
- height:300,
- width: 500,
- modal:true,
- closeOnEscape:true,
- buttons: [ { text: "Close", click: function() { $(this).dialog( "close" ); } } ]
- });
- $("#InsertComment").focus();
- });
- $('#ChangeOfAddress').click(function() {
- //change of address dialog
- $('#change_of_address_form').val('1');
- $( "#ChangeAddressDialog" ).dialog({
- width:500,
- modal:true,
- closeOnEscape:true,
- buttons: [
- { text: "Ok", type: "submit", click: function() { $(this).submit(); $(this).dialog( "close" ); } },
- { text: "Close", click: function() { $(this).dialog( "close" ); } } ]
- });
- });
- $(function() {
- $('#datepicker1,#datepicker2,#datepicker3,#datepicker4').datepicker({
- showOn: 'both',
- buttonImage: 'images/calendar.png',
- buttonImageOnly: true,
- buttonText: 'Select Date'
- });
- });
- </script>
- </body>
- </html>
change of address php page
- <?php
- $Parcel = $_GET($Parcel);
- $Address1 = isset($_POST['Address1']) ? $_POST['Address1'] : null;
- $Address2 = isset($_POST['Address2']) ? $_POST['Address2'] : null;
- $City = isset($_POST['City']) ? $_POST['City'] : null;
- $State = isset($_POST['State']) ? $_POST['State'] : null;
- $Zip = isset($_POST['Zip']) ? $_POST['Zip'] : null;
- $Country = isset($_POST['Country']) ? $_POST['Country'] : null;
-
- class ChangeOfAddress {
- public $Parcel;
- public $Address1;
- public $Address2;
- public $City;
- public $State;
- public $Zip;
- public $Country;
-
- public function SaveToDatabase() {
- $dbc = mysqli_connect(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST) or die ('Error connecting to database.');
- $sql = "INSERT INTO change_of_address (parcel_id, address_1, address_2, city, state, zip, country)
- values ('1','" . $Address1 . "','" . $Address2 . "','" . $City . "','" . $State . "','" . $Zip . "','" . $Country . "')";
- $data = mysqli_query($dbc, $sql) or die ('Error inserting information into the database.');
- mysqli_close($dbc);
- }
- }
- ?>
Thank you for your time!