Welcome Guest, Not a member yet? Register   Sign In
Forms and form action
#1

[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"');?>
anb by logic tried to create send.php file with simple echo command to see is this working. I've saved it in the same dir as form.php file is (form.php is a controller), but this approach isn't working...
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.
#2

[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
#3

[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">
and this is simple straightforward - when you press submit button it will call form.php file and then the rest will happen.
When I generate form with CI using this command
Code:
<?php echo form_open('send', 'class="form"');?>
in source code of the page I receive this
Code:
<form action="http://localhost/ci/send" class="form" method="post">
Since I am thinking the "old way" typical for "old school newbie programmer" this represents an sub directory in ci directory (but as I am reading the book I get that I am wrong and that this has nothing to do with subdirs..).
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 Sad
#4

[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
#5

[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



class Pages extends Controller
{
    
    function Pages ()
    {
        parent::Controller();
    }    
    
    function index ()
    {
        $this->load->view("test");
    }    
}
// end of file
As you can see it only loads view file named test.

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

    echo form_open('form');
    echo form_input('name','Your name');
    echo form_submit('submit', 'Send data');
    echo form_close();
    
?>
Quite simple form, with only one input field and submit button. form_open is calling, if I am right, the file named form.php which resides in controllers folder so I made that file and here is it's source:
Code:
<?php
class Form extends Controller
{
    function index ()
    {
        echo "SENT--------";
    }
}
(I've intentionally left out closing ?> because it states in the manual that closing ?> can be left out)
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?
#6

[eluser]Thorpe Obazee[/eluser]
EDIT: After reading the whole post:

Your code seems correct and should echo only 'SENT--------'.

Are you using any routing?




Theme © iAndrew 2016 - Forum software by © MyBB