0

I have a form in a modal. When I press the submit button the php file runs with the following errors: Notice: Undefined index: phone1 in C:\xampp\htdocs\site\bank.php on line 2 Notice: Undefined index: charge1 in C:\xampp\htdocs\site\bank.php on line 4

Here is the PHP code in bank.php:

<?php
echo  $_POST["phone"];
echo "</br>";
echo  $_POST["charge"];
?>

Here is the modal contents:

<!-- Modal content-->

<div class="modal fade" id="register" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal title here</h4>
      </div>
      <div class="modal-body">
        <form id="modal-form" class="form-horizontal" method="POST" action="bank.php">
          <div class="form-group col-md-12">
            <div class="form-group">
              <div class="col-xs-6" style="float:right;">
                <label>phone numer:</label>
                <input id="phone" type="text" class="form-control" name="phone" value="pre filled value" disabled/>
                <span id='display'></span>
              </div>
              <div class="col-xs-6" style="float:left;">
                <label>charge:</label>
                <input style="font-size:17px; font-weight:bold;" id="charge" type="text" class="form-control" name="charge" value="some other prefilled value" disabled/>
              </div>
            </div>
          </div>
          <div class="form-group">
            <div class="col-xs-12">
              <button class="btn btn-danger btn-default pull-right" data- dismiss="modal" style="margin-left:10px;">close</button>
              <button type="submit" class="btn btn-success"> submit </button>
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        modal footer
      </div>
    </div>

  </div>
</div>

I would be thankful if some one help me figure out what;s wrong with this

3 Answers3

0

The name in your $_POST variable and the html input name are both different. Please try to make them the same and hopefully, your code will work.

Change name=phone1 to name=phone or whatever.

Herry Potei
  • 181
  • 13
0

Not relevant anymore, OP edited his question. see edit for relevant answer!

the name of the post variable is defined by the nameattribute of the input, not the id. therefore in your bank.php you will have $_POST['phone1'] and $_POST['charge1']available. you can always just var_dump($_POST); to see all available post variables.

Edit: Also, disabled inputs are not being sent on submit. You can work around that fact by just adding a second hidden input for each disabled one like that:

<!-- Modal content-->

<div class="modal fade" id="register" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal title here</h4>
      </div>
      <div class="modal-body">
        <form id="modal-form" class="form-horizontal" method="POST" action="bank.php">
          <div class="form-group col-md-12">
            <div class="form-group">
              <div class="col-xs-6" style="float:right;">
                <label>phone numer:</label>
                <input id="phoneDisabled" type="text" class="form-control" name="phoneDisabled" value="pre filled value" disabled/>
                <input id="phone" type="hidden" class="form-control" name="phone" value="pre filled value" disabled/>
                <span id='display'></span>
              </div>
              <div class="col-xs-6" style="float:left;">
                <label>charge:</label>
                <input style="font-size:17px; font-weight:bold;" id="chargeDisabled" type="text" class="form-control" name="chargeDisabled" value="some other prefilled value" disabled/>
                <input style="font-size:17px; font-weight:bold;" id="charge" type="hidden" class="form-control" name="charge" value="some other prefilled value" disabled/>
              </div>
            </div>
          </div>
          <div class="form-group">
            <div class="col-xs-12">
              <button class="btn btn-danger btn-default pull-right" data- dismiss="modal" style="margin-left:10px;">close</button>
              <button type="submit" class="btn btn-success"> submit </button>
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        modal footer
      </div>
    </div>

  </div>
</div>

Edit2: Or, just change disabled attribute to readonly

kscherrer
  • 5,486
  • 2
  • 19
  • 59
0

You have set both of those inputs as disabled. Forms by default won't post those. You probably need to grab the vars with JavaScript, or remove the disabled attributes, again, with JavaScript.

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39