Get form data from Bootstrap 4 Modal

Hi All

I hope I have put this in the correct section.

I am new to Bootstrap etc and need some help getting form data out of a Bootstrap Modal and into a variable so that I can use that information in my PHP code.

Below is my Modal code… I reused the delete confirmation modal however cannot work how to get the email address out of the Modal into a variable.

I am 99.9% sure that it is just a matter of adding a little bit of code to the script at the bottom however I have not been able to work out what needs adding.

Can you help?

Any help would be great.



<!-- EMAIL MODAL -->

<div class="modal fade" id="emailConfirm" tabindex="-1" role="dialog" aria-labelledby="emailConfirmLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title main-heading-colour" id="emailConfirmLabel">EMAIL CONFIRMATION</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button>
      <div class="modal-body">
	    <label for="exampleInputEmail1">Email invoice to...</label>
	    <div class="form-group">
    	  <input type="email" class="form-control" id="" name="" aria-describedby="invoiceEmailAddress" placeholder="Enter Invoice Email Address" value="<?php print $invoiceEmailAddress; ?>">
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary w-50" data-dismiss="modal">CLOSE</button>
        <a href="admin.php?action=manageInvoice&nav=accounts&invoiceID=<?php print $invoiceID; ?>&uniqueID=<?php print $uniqueID; ?>&internalAction=emailInvoice&uniqueID=<?php print $invoiceRow['uniqueID']; ?>" id="email" class="btn btn-success w-50">EMAIL NOW</a> </div>
$( document ).on( "click", "email", function() {

Hi there…

  1. Firstly you need to be wrapping your form fields in a form element:
<form method="post">
html fields here...
  1. Secondly you should give a name attribute to all your fields:
<input name="email-field" type="email" class="form-control" aria-describedby="invoiceEmailAddress" placeholder="Enter Invoice Email Address" value="<?php print $invoiceEmailAddress; ?>">
  1. Thirdly the field’s data will reside in the $_POST array after you submit the form:

if (!empty($_POST)) {
    if (!empty($_POST['email-field'])) {
        $email = $_POST['email-field'];
        // do something here with email ...

Hope this helps setting you in the right direction.

Thanks… that was a lot easier than I realised.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.