Welcome Guest, Not a member yet? Register   Sign In
calling controller function
#1

[eluser]Rahul gamit[/eluser]
I want to call controller function named as CreateData() on submit button click,but its not working.

here is my code.
Code:
<form method="post" >
<input type="submit"  value="CREATE" name="btncreate" id="btncreate" />        
</form>

//controller code

Code:
function CreateData()
{    
if($this->input->post('btncreate'))
$this->load->view('demo');
}
#2

[eluser]SPeed_FANat1c[/eluser]
you must set action attribbute in your form

http://www.w3schools.com/TAGS/att_form_action.asp
#3

[eluser]Rahul gamit[/eluser]
actually i tried both the way but it wont work..
#4

[eluser]SPeed_FANat1c[/eluser]
so maybe youre getting some errors?
#5

[eluser]Rahul gamit[/eluser]
see when i am doing it for different form then it works fine.

here is the code for which it works good.
Code:
//view
<form method="post">
    <div>
        
        <label for="txtTitle">Title</label>
        &lt;input type="text" id="txtTitle" name="txtTitle" /&gt;
        <br />
        
        <label for="txtContent">Content</label>
          <br />
        &lt;textarea id="txtContent" name="txtContent" &gt;&lt;/textarea>
        [removed]
            CKEDITOR.replace( 'txtContent' );
        [removed]
              
    </div>
        

        &lt;input type="submit" id="btnSubmit" name="btnSubmit" value="Submit"/&gt;
&lt;/form&gt;

//controller code
function AddSystemSolution()
    {
        $this->load->view('ViewInsertData');
        if($this->input->post('btnSubmit')==TRUE )
        {
            $this->ModelSystemSolution -> InsertData();    
            redirect('http://localhost:8080/Codeigniter/index.php/ControllerName/GetAllSystemSolution/','refresh');
        }
    }

but the problem is that k when i am doing it for the question which i have posted then it wont work Sad
#6

[eluser]SPeed_FANat1c[/eluser]
Try copying the controller code which works but use the the form which does not work. Is it working now? And what do you get, you should get some errors or something if it does not work.

(leave the btncreate in this input post, because otherwise it will not recognize )
#7

[eluser]Rahul gamit[/eluser]
Thanks,
i got the answer,and now it works fine.
thank you all.
#8

[eluser]SPeed_FANat1c[/eluser]
so where was the problem, it would be interesting to know Smile
#9

[eluser]Rahul gamit[/eluser]
I have to include action attribute for &lt;form action=""&gt; if you want to redirecting the different page.
#10

[eluser]InsiteFX[/eluser]
Load the form_helper:
Code:
echo form_open('controller_name/method_name');

Simple!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB