-1

I'm just new to CodeIgniter framework and all the lessons have been jumbled on my mind now. I just want to ask, how to submit a form without using a form submit button in codeigniter. I did saw an example of javascript but I want to see it in codeigniter framework. Can anybody give me a simple mvc sample? Thank you in advance!

BlackSkull
  • 193
  • 1
  • 16

1 Answers1

2

you can use AJAX as well

<script>
    $(function(){
        $( "#submit" ).click(function(event)
        {
            event.preventDefault();
            var name= $("#name").val();
            var phone= $("#phone").val();
            var address= $("#address").val();

            $.ajax(
                {
                    type:"post",
                    url: "<?php echo base_url(); ?>index.php/Controller_name/Method name",
                    data:{ name:name, phone:phone,address:address,},
                    success:function(data)
                    {

                    }
                    error:function(data)
                    {

                    }
                });
        });
    });
</script>

So in Form should be

<form action="#" method="post">

    <input type="text" id="name" name="name">
    <input type="text" id="phone" name="phone">
    <input type="text" id="address" name="address">

    <input type="submit" value="Submit Form" id="submit">
</form>
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
  • This answer is correct but if you don't want to use a submit button you should remove ` – Daniel Waghorn Jul 16 '15 at 07:52
  • what if I don't want to use a submit button? it's like a live preview of your work that you don't need any button to submit it but automatically submit it once you in fill that field or once you edit it. – BlackSkull Jul 16 '15 at 07:54
  • @BlackSkull this will be bad habit. If user mistakenly enter wrong data and if he want to recheck it, he cant do that cz form get submitted – Abdulla Nilam Jul 16 '15 at 07:56
  • check [this link](http://stackoverflow.com/questions/12376173/auto-submit-form-using-javascript) – Abdulla Nilam Jul 16 '15 at 07:58
  • uhm, the one I saw here in this company that I've been working on, you never leave that form window/page. so if ever you have type a wrong data at that field, you can edit it again. I checked the source code of that form but I can't understand some parts of it especially that I just new to MVC framework and that code was paralled to YII. and I don't even know how YII works too. So I'm totally lost. but, thank you for answering this! I'll check that and the source code to get any more ideas. Thank you very much. – BlackSkull Jul 16 '15 at 08:10