-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!

1
  • Did you try some thing ? Commented Jul 16, 2015 at 8:27

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

5 Comments

This answer is correct but if you don't want to use a submit button you should remove <input type="submit" ... from your form, then simply attach the click event handler to whatever you want to use to invoke the submission.
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 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
check this link
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.