Forms and form action |
[eluser]zlatiborac[/eluser]
After yesterdays mistakes :red: today I found a book and tried to make a form via form_ commands. And that part was successful, and I even managed to style the form using the CSS file. But now I have a question. I want to send data from this form to page and then insert this data into database. So I've used Code: <?php echo form_open('send', 'class="form"');?> Am I saving it in the wrong place or my approach is wrong? It would be nice if someone has time to explain me this or to point me to some tutorials on the web ... Thanks guys.
[eluser]Dam1an[/eluser]
Hi, first of all, a good place to start, is the form helper in the user guide When using form_open, you use the controller/method, I normally use the controller which called the form, and then process_ name of method which called the form, eg 'account/process_login' If you have any other questions, just ask
[eluser]zlatiborac[/eluser]
Thanks for this fast reply... Well I've read form helper and that area is not the problem (generating the form, customizing...). Generally what is confusing me in CI are file paths. I'll give you an example. In "normal" form you have this Code: <form action="form.php" method="POST"> When I generate form with CI using this command Code: <?php echo form_open('send', 'class="form"');?> Code: <form action="http://localhost/ci/send" class="form" method="post"> I've tried to add function send in controller that called the form but no success. I hope that you now understand where I am stuck ![]()
[eluser]Dam1an[/eluser]
The generated URI for the form (http://localhost/ci/send) your base URL is http://localhost/ci, send is the controller, and as no method has been specified, it will default to the index function in the send controller If you want to process the form in a differant function, just add the function name to the form_open (eg 'send/process') I hope this makes sense
[eluser]zlatiborac[/eluser]
OK, I made simple example of how I did this so here it is: first I made controller named pages.php and I saved it in application/controllers folder. Here is the source: Code: <?php After this I made a file called test.php and saved it in my application/views folder. Here is the source from that file: Code: <?php Code: <?php Now when I click on submit button all I get is this form again (if I change "Your name" in something else and after I click on button I get the same form with "Your name" in input field; so it is reloading the same form again). This is the way I did this and how I understood you reply... Am I correct?
[eluser]Thorpe Obazee[/eluser]
EDIT: After reading the whole post: Your code seems correct and should echo only 'SENT--------'. Are you using any routing? |
Welcome Guest, Not a member yet? Register Sign In |