calling form_open using a button in codeigniter - php

I want to call a method in my controller class at a button press. want to know how this should be corrected. or is there any other reason that this won't work.
<?php echo form_open('form/SearchUser');?>
<button type="submit" class="btn btn-default">Search</button>
<?php echo form_close();?>

Related

How to place two submit button in a view page with different action in a controller using codeigniter version 3

I have home_c controller, home_m model and home_v view page in code igniter application folder. My view home_v page contains following code.
<?php
echo form_open('home_c/save');?>
Name:<input type="text" name="name" value="">
<input type="submit" name="sub" value="Save">
<?php echo form_close();?>
<?php
echo form_open('home_c/view');?>
<input type="submit" name="view" value="View">
<?php echo form_close();?>
My problem is that, I could not execute function view() in controller home_c. But I can execute same function by placing instead of the view button. I don't know what is the real issue behind this. Anybody please help me to solve this issue.
If you want different action for each button, use the a href = base_url 'Controller/Method'.. Like this one, button type = "button" a href=" base_url() . 'Controller/Method'
if($this->input->post('sub')=='Save'){
$this->your_model->add($data);
}
if($this->input->post('view')=='View'){
$this->load->view('view',$data);
}
Change like this and check

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

Codeigniter link button to another view not working?

<button onclick="location.href='<?php echo base_url();?>Guesser/guess'">Start!</button>
Just displays an empty web page with about:blank as the url
Try this:
<input type="button" onclick="location.href='<?php echo base_url();?>Guesser/guess'" value="Start!">

Unable to reset form in codeigniter

I'm using three different methods to reset my form, but still nothing happens after I click the buttons, Here is my form's structure:
Any help would be appreciated
$this->load->helper('form');
$attributes = array('class' => 'form-inline', 'id' => 'ProductForm');
echo form_open_multipart("product/process/$id",$attributes);
.
.
.
<?php echo form_reset(array('id'=>'reset','value'=>'resetme'));?>
<button onclick="ResetForm();">Reset Form</button>
<button type="reset" value="Reset">Reset</button>
<?php echo form_close();?>
<script>
function ResetForm() {
document.getElementById("ProductForm").reset() ;
}
</script>
//same for form_open()
Did you also try
<input type="reset" value="Reset">
#Mahdi Younesi: Just use the input type reset and then test it will reset the form elements.
first add some input types in form to test the reset function
here is the solution
add one input in form and than
replace form_reset(array('id'=>'reset')); to form_reset(array('id'=>'reset','value'=>"resetme"));

Angularjs: how to Call method in Controller while submitting the Form

Actually In my form page of Angularjs, have two submit buttons i.e In one field set i have one button for update and another button at the outside of all field sets for submission of whole page.
Code
<form ....... data-ng-submit="Register()">
<fieldset>
............
.............
<div data-ng-submit="update()">
<button type="submit" class="btn btn-success">Update Vehicle</button>
</div>
</fieldset>
<fieldset> .........</fieldset>
</form>
After submission of form to the ctrl
.ctrl(function(){
**we have two methods in it.......**
$scope.update=function(){
}
$scope.register=function(){
}
}
While updating the fieldset it goes to register method and its executes the logic in it.
how to format the data-ng-submit="update()", such that it will call the update() method in Controller

Categories