-1

i have set the form action to a text retrieved from the database which has an id.my problem is when the form action executed it always shows the first id even if i clicked on the text holding id=2.I have checked the page source and it's showing the correct id for all the text.

here is my view code

<?php foreach ($content as $cont):?>
<form id="offer" method="post" action="<?php echo base_url() . 'index.php/pages/detail'?>">
<input type='hidden' name='cont_id'id='cont_id' value='<?php echo $cont->id?>'>
<a onclick="document.getElementById('offer').submit();"><?php echo $cont->title?></a>
</br>
</form>
<?php endforeach;?>
</div>
<script>
    function submitForm() {
      document.getElementById("offer").submit();}
</script>

here is my controller :

echo $this->input->post('cont_id');
Taryn
  • 242,637
  • 56
  • 362
  • 405
Rahat Islam Khan
  • 125
  • 1
  • 6
  • 25

2 Answers2

0

You can use .submit()

<a href="#" onClick="document.getElementById('yourFormID').submit();">Submit</a>
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
0

If you have JAVASCRIPT knowledge you can use the

document.getElementById("myForm").submit();

method to submit the form..

create a Javascript Function

    <script>
             function submitForm() 
             {
                   document.getElementById("myForm").submit();
             }
   </script>

use this code for the text you want to hyperlink the button to

<h1 onclick="submitForm()">Click on this text</h1>
Ashrith Sheshan
  • 654
  • 4
  • 17