codeigniter - How to Post values outside the form in php

916

I need to post values outside the form in php , How to do it

Here is my sample code

<input type="hidden" id="test" name="test" />
<input type="hidden" id="testvalue" name="testvalue"/>
<?Php for($i=0;$i<5;$i++) { ?> 
     <form action='some_url'>
         <input type="text" value="dynamic_value" name='testname'>
      <select name="testselect">
  <option value="<?php echo $dynamicvalue[$i]?>"><?php echo $dynamicvalue[$i]?></option>
        </select>
    <button class="btn btn-primary book_now" type="submit">BookNow</button>

     </form>
  <?php } ?>

i need to post all input values above the form also,since i cannot use that input field inside the loop, i want id to be unique so i cant use inside

any other option available to post all data

951

Answer

Solution:

Use jQuery:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
$(document).ready(function(){
    $('form').submit(function(){
        var test = $('#test').val();
        var testvalue = $('#testvalue').val();
        $(this).append('<input type="hidden" name="test" value="'+test+'">');
        $(this).append('<input type="hidden" name="testvalue" value="'+testvalue+'">');
        return true
    });
});
</script>
395

Answer

Solution:

You can add input fields into for-loop

<?php for($i=0;$i<5;$i++) { ?> 
    <form action='some_url'>
        <input type="text" value="dynamic_value" name='testname'>
        <select name="testselect">
            <option value="<?php echo $dynamicvalue[$i]?>"><?php echo $dynamicvalue[$i]?></option>
        </select>
        <button class="btn btn-primary book_now" type="submit">BookNow</button>
        <input type="hidden" name="test" />
        <input type="hidden" name="testvalue"/>
    </form>
<?php } ?>

People are also looking for solutions to the problem: MySQL in PHP can't get values that are equal

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.