manjusha manjusha - 4 months ago 18
PHP Question

form_open not working inside codeigniter controller

I want to echo a form inside controller. In that i wrote echo form_open, but it is not working.
Here is my code inside controller function

echo '<button class="btn btn-primary" data-toggle="modal" style="background-color:#428bca;" data-target="#myModal" ></button>';

echo '<div class="modal fade bs-example-modal-sm" tabindex="-1" id="myModal" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">';
echo '<div class="modal-dialog modal-sm">';
echo '<div class="modal-content">';
echo ' <div class="modal-header">';
echo '<button aria-hidden="true" data-dismiss="modal" class="close" type="button">&times;</button>';
echo '<h4> Do you </h4>';?>

<?php echo form_open('amt_controller/add_amount/'.$schoolID."/".$stID);

echo '<input type="name" class="form-control" name="Amount" id="Amount" placeholder="Enter the amount">';

echo '</div>';
echo '<div class="modal-body">';
echo '<button class="btn btn-primary" style="margin-left:65px;background-color:#428bca;">Submit</button>';?>
<?php echo form_close();
echo '<button type="button" class="btn btn-default" data-dismiss="modal">No</button>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';

Answer

Remove the php tags on form open and close and put them like

<?php

echo '<button class="btn btn-primary" data-toggle="modal" style="background-color:#428bca;"  data-target="#myModal" ></button>';

echo '<div class="modal fade bs-example-modal-sm" tabindex="-1"  id="myModal"  role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">';
echo '<div class="modal-dialog modal-sm">';
echo '<div class="modal-content">';
echo ' <div class="modal-header">';
echo '<button aria-hidden="true" data-dismiss="modal"  class="close" type="button">&times;</button>';
echo '<h4> Do you </h4>';?>

form_open('amt_controller/add_amount/'.$schoolID."/".$stID);

echo '<input type="name" class="form-control"  name="Amount" id="Amount" placeholder="Enter the amount">';

echo '</div>';
echo '<div class="modal-body">';
echo '<button class="btn btn-primary" style="margin-left:65px;background-color:#428bca;">Submit</button>';?>

echo form_close();

echo '<button type="button" class="btn btn-default" data-dismiss="modal">No</button>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';

?>
Comments