Welcome Guest, Not a member yet? Register   Sign In
I have problem with post form with jquery
#21

[eluser]Thorpe Obazee[/eluser]
[quote author="painting753" date="1246222199"]If your just using the controller name because your looking for an easy url, maybe you could try setting up a route that would direct to the needed function. I don’t know of any restrictions..

Also, if your using jQuery to perform your post, there is no need to wrap your inputs in a form tag. The form tag is used to bundled everything up when you use an html submit button. It finds all inputs within that form tag and submits those. Using jQuery you have specifically tell it what items to send, eliminating the need for the form tag.

Regards & Thanks

Harry

Picture to Painting
Photo to portrait[/quote]

Spam: Copied from: http://ellislab.com/forums/viewthread/121102/#601140
#22

[eluser]pickupman[/eluser]
Be careful when removing the <form> tag as your page will not degrade gracefully if someone has javascript disabled.
Build your form as usual, and then implement jQuery 2nd.
#23

[eluser]darkside9[/eluser]
Thanks Guys
My problem occurred because I forget adding the language before the controller name, and my problem with form submission with jquery occurred when I forget adding the language before the controller name.

Code:
<form id=“search_form” action=”<?php echo site_url()?>en/search” method=“post”>
        <div>
          &lt;input type=“text” align=“bottom” class=“search_box” name=“query” id=“query” value=”” /&gt;
          &lt;input type=“image” align=“top” src=”/images/search-button.png” id=“submit” value=“Search” /&gt;
        </div>
      &lt;/form&gt;


Code:
class Search extends Controller {
    function Search(){
        parent::Controller();
    }
    
    function index(){
        echo $this->input->post('query'); //but this did not echo any thing
    }
    
    
}

the above code working fine Smile
#24

[eluser]pickupman[/eluser]
For your &lt;form&gt; tag you should change your action attribute to:
Code:
&lt;?php echo site_url('search');?&gt;
CodeIgniters URLs are /class/function/id so by prefixing /en/search you would be posting to the controller en.php not search.php. Unless you have CI running in a subdirectory for different languages.
For jQuery you can use
Code:
<scr|pt type="text/css">
jQuery(document).ready(function($){
   $("#search_form").submit(function(event){
        var text = $('input[name="query"]').val();
        $.post('&lt;?php echo site_url('search');?&gt;',{query: text},function(data){
            alert(data);
        });
        return false;
   });

});
</scr|pt>
This should echo back the results from the form.




Theme © iAndrew 2016 - Forum software by © MyBB