two submit button inside one form in codeigniter - php

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" />

Related

How to register button click

html:
<button type="button" class="btn btn-outline-danger btn-icon-text" id = "LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
php:
<?php
if (isset($_SESSION['LOAD']))
{
exit();
}
?>
when i click the button, nothing happens. sorry i am really new to html and php. i have tried multiple other methods but none work :(
<button type="button" class="btn btn-outline-danger btn-icon-text" id = "LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
That's just a HTML code, so it will not trigger anything. You need little bit javascript.
Also remember, php loads before javascript. So you can't trigger php with javascript if you don't use AJAX or redirect etc.
<script>
document.getElementById("LOAD").onclick = function(){
window.location.href = window.location.href+"?LOAD=1";
}
</script>
If you add that javascript code, button will refresh the page and redirect the same page with GET parameter.
You can control the GET parameter on the PHP side.
<?php
if (isset($_GET['LOAD']))
{
exit();
}
?>
It's not efficient path but if you understand the mechanics, you can figure it out.
Research AJAX.
You are not assigning the button name (which is different from the id)
try name="LOAD" as in:
<button type="button" class="btn btn-outline-danger btn-icon-text" id="LOAD" name="LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
</div>

disable a submit button after clicking on it in codeigniter

I'm new to php and codeigniter. I have this task that i'm working on right now which is a hostel management system. the student has the ability to choose the meal they want to eat by selecting on it, all im trying to do is to disable the select button after they click on it, in other words the student can choose a specific meal once.
here's my code:
<td><div><?php echo $row['type'];?></div></td <td><div><?php echo $row['content'];?></div></td>
<td><div><?php echo $row['date'];?></div></td>
<td align="center">
<?php $is_selected=$this->db->get_where('selected_meal', array( 'meal_id' => $row['meal_id'],'student_id'=>$this->session->userdata('student_id')))->row()->delivered;
<a data-toggle="modal" href="#modal-form" onclick="modal('order_meal',<?php echo $row['meal_id'];?>)" class="btn btn-gray btn-small">
<i class="icon-wrench"></i> <?php echo get_phrase('select');?>
</a>
<?php ?>
</td>
Here is sample form, button and javascript. You need to modify it to fit your needs.
<form name="myForm" id="myFormId" class="form-horizontal" method="post" action="<?=base_url('invoice/create_invoice');?>">
<input type="submit" id = "formSubmit" class="btn btn-primary" value="Submit">
</form>
<script type="text/javascript">
document.getElementById('myFormId').onsubmit = function() {
document.getElementById("formSubmit").disabled = true;
}
</script>
Give a class to element, which you want to select. Ex 'select-meal'.
$('.select-meal').click(function(){
$(this).attr('disabled', 'true');
})
It seems you are using bootstrap, you can add class "disabled" on click submit
Or, try this, add class dis-btn and write script on event click
$('.dis-btn').prop('disabled', true);

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>

How to remove button after submit form using PHP

I need one help.I need to totally remove the submit button after submit the form and when it will be submitted the button will display to user.I am explaining my code below.
<form name="billdata" id="billdata" enctype="multipart/form-data" method="POST" onSubmit="javascript:return checkForm();" action="complain.php">
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px"> Name :</span>
<input type="text" name="u_name" id="name" class="form-control" placeholder="Add Name" onKeyPress="clearField('name');">
</div>
<input type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit"/>
</form>
complain.php:
require_once("./include/dbconfig.php");
if(isset($_REQUEST['complainSubmit']))
{
// ......data is collecting here....
}
when data are submitted successfully the below part is executing.
<script type="text/javascript">
var phpVar = "<?php echo $_GET['success'];?>";
//console.log('php',phpVar=='');
if(phpVar == 1 && phpVar!=''){
alert('Submitted successfully.');
//var subButton=document.getElementById('addProfileData');
//subButton.disabled=false;
}
else if(phpVar == 0 && phpVar!=''){
alert('Unable to add.\\nTry again.');
}
else{
// nothing
}
</script>
<script>
function checkForm(){
var s=document.billdata;
if(s.u_name.value==''){
alert('Please enter name');
s.u_name.focus();
s.u_name.style.borderColor = "red";
return false;
}
}
</script>
Here i need to button hide when the data is going to submit and it will again display after the submit.Please help me.
A javascript code such as:
document.getElementById("your_div").innerHTML = "";
will erase the content of your div.
So, byt tagging the entire form, then erasing its contents, you can "hide" it.
Why you dont add a hide CSS-Selector or remove it by checking via if-statement?
CSS-Version:
<input type="submit" class="btn btn-success <?php ($isSubmitted ? ' hideme' : '')?>" name="complainSubmit" id="addProfileData" value="Submit">
Except a new CSS-Selector: .hideme { display:none }
Via PHP/Template:
html...
<?php if(!$isSubmitted) : ?>
<input type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit">
<?php endif; ?>
html...
Dont forget: You dont need close input html-tag: <input/> just <input>
And what is wrong to hide the button via JS?
document.getElementById("addProfileData").style.display = "none";
UPDATE:
Prompt hiding after clicking:
<button onclick="javascript:this.style.display='none'">
Submit Button
</button>
in your example:
<input onclick="javascript:this.style.display='none'" type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit"/>

Wordpress submit a form, update link with form input and go to that link & link is "#"?

This code is a form that results in a link being created with variable $ui.
<form method="post" name="form" onsubmit="#">
Name search:
<input id="ui" type="text" name="ui" />
<input type="submit" class="Submit" value="submit" />
</form>
Then the variable $ui is used to set the value of the data-filter attribute. When you click the link (after the form submits) it goes to "#" which performs a sorting/listing function and reloads the page without refreshing.
<?php if(isset($_POST["ui"]))
{
$ui = $_POST["ui"];
}
$Filterclass = strtoupper(str_replace(" ", "-", $ui));
?>
<a href="#" id="gallery_filter"
data-filter=".<?php echo $Filterclass; ?>">
<?php echo strtoupper($ui); ?></a>
Right now, the form submits and then the link is created, then you can click on it.
It works as-is, but I'd like to have the 'submit' button just open that link, the one with newly updated data-filter attribute.
I would ask this is Wordpress.exchange but I think is too advanced.
I won't write the whole process but modify your existing code as below(assuming jquery is already loaded)
<?php if(isset($_POST["ui"]))
{
$ui = $_POST["ui"];
echo '<script type="text/javascript">
jQuery(document).ready(function(e){
jQuery("#gallery_filter").click();
});
</script>';
}
$Filterclass = strtoupper(str_replace(" ", "-", $ui));
?>
<a href="#" id="gallery_filter"
data-filter=".<?php echo $Filterclass; ?>">
<?php echo strtoupper($ui); ?></a>

Categories