How to put multiple submit buttons in codeigniter - php

i have designed this form for login modal:
<tr>
<td></td>
<td><?php echo form_submit('submit', ' Log In', 'class="btn btn-primary btn-lg btn-block"'); ?>
<?php echo form_submit('forget', ' Forget Password ', 'class="btn btn-warning btn-lg btn-block"'); ?>
</td>
</tr>
both of these buttons are doing same works how can I isolate which one has pressed?
thanks for everyon

You can obtain this by using this HTML:
<tr>
<td></td>
<td>
<button type="submit" name="action" value="submit" class="btn btn-primary btn-lg btn-block"> Log In </button>
<button type="submit" name="action" value="forget" class="btn btn-warning btn-lg btn-block"> Forget Password </button>
</td>
</tr>
Then use the POST data like this:
$action = $this->input->post('action');
if($action == 'submit') {
// execute code to log in
}
if($action == 'forget') {
// execute code to forget the password
}

if (!empty($_POST['submit'])) {
// submit button pressed
}
if (!empty($_POST['forget'])) {
// forgot password button pressed
}

Have you tried this:
if($this->input->post('submit'))
{
// what to do in case of submit
}
if($this->input->post('forget'))
{
// what to do in case of forget
}

In the view use a multipart form instead of a normal form.Like this
<?php echo form_open_multipart('Controller/function')?>
Then simply use your submit buttons
Then again in the controller use post with submit fields names
if($_POST['SUBMIT1'])
{
//code
}
if($_POST['SUBMIT2'])
{
//code
}

Related

my code is only returning one section of the code

<?php
if(!$product_kit_rage) {
echo '<button type="button" class="btn btn-secondary">Purchase Now</button>';
} else {
echo '<button type="button" class="btn btn-success">Download</button>';
}
?>
This code only seems to display the first section of the echo
example:
<button type="button" class="btn btn-secondary">Purchase Now</button>
the variable is already stored in via
include_once("/home/user/public_html/resource/session.php");
my aim is when its got a value of 1 in product_kit_rage it returns
<button type="button" class="btn btn-success">Download</button>
If you want to show download button when product_kit_rage is 1:
<?php
if ( $product_kit_rage == 1 ) {
echo '<button type="button" class="btn btn-success">Download</button>';
} else {
echo '<button type="button" class="btn btn-secondary">Purchase Now</button>';
}
?>

Post 2 different form actions with 2 submit buttons

I have a table where I use an UPDATE button with action form to update the data. But I also need to submit the table using another form action and submit button.
Here's my button:
<button class="btn btn-info" type="submit" name="update" value="update">Update Table</button>
<button class="btn btn-success" type="submit" name="submit_req" value="submit_req">Submit Request</button>
This is currently my form action for the table:
<form method="post" action="">
And this is my PHP if else statement. The first submit_req is supposed to POST to another URL. But I don't know how to do it. I already tried header, but it won't work.
<?php
if(isset($_POST['update'])){
if(!empty($_SESSION['cart'])){
foreach($_POST['quantity'] as $key => $val){
if($val==0){
unset($_SESSION['cart'][$key]);
}else{
$_SESSION['cart'][$key]['quantity']=$val;
}
}
}
}elseif (isset($_POST['submit_req'])) {
//form action: insert_order.php
}
?>
You can use a JS function to redirect to another page for the submit button
Here page.php is where you want to send your form to. formID is the id of the form.
<button class="btn btn-success" type="submit" name="submit_req" value="submit_req" onclick="submitForm('page.php')">Submit Request</button>
<script type="text/javascript">
function submitForm(action)
{
document.getElementById('formID').action = action;
document.getElementById('formID').submit();
}
</script>

two submit button inside one form in codeigniter

hi i want to have two submit button in one form in code igniter. is it possible? i want to make two buttons which will do the same thing, add data into the database, the only difference of the buttons is on which page they will redirect.
here is my codes,
<?php
echo form_open('EmpFamilyInfo/add_childinfo/'.$this->uri->segment(3));
?>
// some textboxex,
<div class="box-body">
<div class = 'col-md-6 col-sm-offset-6'>
<button class="btn btn-info fa fa-save" type="submit">&nbsp Save</button>
<a href = '<?php echo base_url().'EmpFamilyInfo/other_childinfo/'.$this->uri->segment(3); ?>' class = 'btn btn-primary fa fa-save' >&nbsp Add Another</a>
<a href = '<?php echo base_url().'EmpFamilyInfo/parentsinfo_father/'.$this->uri->segment(3); ?>' class = 'btn btn-danger fa fa-arrow-circle-right'>&nbsp Skip</a>
<?php
echo form_close();
?>
</div>
</div>
i have made this code which the first link echo form_open('EmpFamilyInfo/add_childinfo/'.$this->uri->segment(3)); what i wanted this to do is
public function other_childinfo(){
$this->form_validation->set_rules('NAME', 'Name of Child' ,'trim|required|max_length[100]');
if($this->form_validation->run($this) == FALSE){
$this->child_info();
}else{
if($query = $this->EmpFamilyInfo_Model->insert_childinfo()){
redirect('EmpFamilyInfo/child_info/'.$this->uri->segment(3));
}else{
$this->child_info();
}
}
}
but the error is,that it does not have post data. how can i make this link a submit button but it will go to different function or how can i make it have the post data?
this question ahs been answered already on this site, so this response is not mine, just quoting for you:
This uses javascript so keep in mind users who have this disabled will not be able to use this solution.
<script type="text/javascript">
function submitForm(action)
{
document.getElementById('form1').action = action;
document.getElementById('form1').submit();
}
</script>
...
<input type="button" onclick="submitForm('page1.php')" value="submit 1" />
<input type="button" onclick="submitForm('page2.php')" value="submit 2" />

HTML form not working. Isset POST doesn't work PHP.

I want add records into the base but not all. I have checkboxes and if some is checked then I add into the base if i click input button Save("Zapisz zmiany").
But input button save doesn't work. No reaction. POST array is empty. I don't know what i am doing wrong.
Input button:
<form action"" method="post" >
<input type="button" class="btn btn-primary" data-dismiss="modal" value="Zamknij/Close" />
<input type="button" class="btn btn-primary" name"zapros" id="zapros" value="Zapisz zmiany" />
</form>
and:
<?php
if (isset($_POST['zapros'])) {
$sqlc=mysqli_connect('127.0.0.1','root','');
if($sqlc) {
$sql_q="USE aplikacja";
mysqli_query($sqlc,$sql_q);
$data_zaproszenia = date("Y-m-d");
$sql_q=mysqli_query($sqlc, "SELECT * FROM goscie WHERE Email_goscia= '$mail'");
if(mysqli_num_rows($sql_q) != 0)
{
for ($i=1; $i < $lp ; $i++)
{
if (isset($_POST['zaznacz'.$i.'']))
{
$data_waznosci = $_POST['data_waznosci'.$i.''];
$sql_zaproszenie=mysqli_query($sqlc, "INSERT INTO zaproszenia (Email_goscia, ID_kwestionariusza, ID_wyniku, Data_zaproszenia, Data_waznosci, Wynik, Ocena, Status)
VALUES ('$mail', $id, NULL, '$data_zaproszenia', '$data_waznosci', NULL, NULL, 'Status')"); //dodawanie kolejnych odpowiedzi do bazy
echo "<script type='text/javascript'>alert('Zaproszenie wysłano!');</script>";
header('Refresh: 0;url=zaproszenia.php?id='.$id.'');
}
else
{
echo "<script type='text/javascript'>alert('Zaproszenie NIE wysłano!');</script>";
$i++;
}
}
}
mysqli_close($sqlc);
}
else
{
echo mysqli_connect_errno();
}
}?>
I haven't even examined your PHP, but you have some errors in your HTML:
<form action="" method="post" >
<input type="button" class="btn btn-primary" data-dismiss="modal" value="Zamknij/Close" />
<input type="submit" class="btn btn-primary" name="zapros" id="zapros" value="Zapisz zmiany" />
</form>
You were missing = signs in two places (action= and name=), and were using a button instead of a submit button.

How to handle two submit buttons in my form

I am trying to create two submit button in my form
<form id="form-input-wrapper" action='test.php'>
//form items..
//form items..
<button class="btn btn-primary" type="submit" value="old">first button.</button>
<button class="btn btn-primary" type="submit" value="new">second button</button>
</form>
My question is how to distinquish which button the user clicks in my test.php page?
You need to add the name attribute to your buttons
<button class="btn btn-primary" type="submit" name="old" value="old">first button.</button>
<button class="btn btn-primary" type="submit" name="new" value="new">second button</button>
The php code to use would look like:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
//something posted
if (isset($_POST['old'])) {
//old
} elseif (isset($_POST['new']){
//new
}
}
related question:
How can I tell which button was clicked in a PHP form submit?
Use button name tag and check them in php:
<button name="subject1" type="submit" value="HTML">HTML</button>
<button name="subject2" type="submit" value="CSS">CSS</button>
And in php:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ( isset($_POST['subject1']) ) {
// first button is clicked
} elseif ( isset($_POST['subject2']) ) {
//second button is clicked
}
}
?>

Categories