简体   繁体   中英

how to get data from input in modal html?

Trying to get trkodep from input and post it to /ppp/trkodeptoyek but when I push the button it's doesn't go to /ppp/trkodeproyek but it stay in form where I put the modal (it's like I only close the modal).

 <div class="modal-body">
      <form action="<?php echo base_url().'index.php/ppp/trkodeproyek';?>" method="POST">
      <input type="text" name="trkodep" placeholder="kode proyek"/>
      <input type="submit">
      </form>

Try this

  <div class="modal-body">
  <form method="POST"  action="<?php echo base_url()?>index.php/ppp/trkodeproyek">
  <input type="text" name="trkodep" placeholder="kode proyek"/>
  <input type="submit">
  </form>

You should try using Javascript:

 <div class="modal-body">
    <form id="form" action="<?php echo base_url().'index.php/ppp/trkodeproyek';?>" method="POST">
      <input type="text" name="trkodep" placeholder="kode proyek"/>
      <input type="submit" onclick="form_submit()">
    </form>

 <script type="text/javascript">
  function form_submit() {
    document.getElementById("form").submit();
   }    
  </script>

base_url is not a builtin function. so I can't know where you want.

If you want to go to the path under the current page, use relative path.

<form action="ppp/trkodeproyek" method="POST">

If ppp is under the root path, add a slash at beginning.

<form action="/ppp/trkodeproyek" method="POST">

Try this

 <div class="modal-body"> <form action="<?PHP echo base_url().'index.php/ppp/trkodeproyek'; ?>" method="POST"> <input type="text" name="trkodep" placeholder="kode proyek"> <input type="submit"> </form> </div> 

Or change the form tag into this <form action="<?PHP echo base_url(); ?>index.php/ppp/trkodeproyek" method="POST">

  • Make sure that the function base_url() is returning some value, if you are not sure, use <?PHP echo base_url(); ?> <?PHP echo base_url(); ?> outside of the form and look if it is retuning some value
  • in your web browser, give right click in the textbox and select inspection, look what is the full URL of the action of the form

is your function to get the value from that form is on index.php? then if it yes, use this

<div class="modal-body">
  <form action="<?php echo base_url().'/ppp/trkodeproyek';?>" method="POST">
  <input type="text" name="trkodep" placeholder="kode proyek"/>
  <input type="submit">
  </form>

I don't know why my form action doesn't work here so I using <a> and javascript for direct to my function, and it's work.

 <input class="trkode" type="text" name="trkodep" placeholder="kode proyek"/>


      <a class="btn btn-default btntrk" href="<?php echo base_url().'index.php/ppp/trkodeproyek';?>" style="margin-top: 10px; margin-bottom: 10px;">kirim</a>
      <script type="text/javascript">
        function form_submit() {
          document.getElementById("form").submit();
        }
        $(".trkode").change(function(){
            //alert('anda telah memasukan kode proyek');
            var trkode = $(this).val();
            $(".btntrk").attr("href", "<?php echo base_url().'index.php/ppp/trkodeproyek/';?>"+trkode);
        });   
      </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