CodeIgniter Forums
NEWBIE ALERT! - Basic Form: Please help me find my fault - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: NEWBIE ALERT! - Basic Form: Please help me find my fault (/thread-42821.html)



NEWBIE ALERT! - Basic Form: Please help me find my fault - El Forum - 06-20-2011

[eluser]John Lopez[/eluser]
Message:
Hi guys! I am new to CI and is starting to play around with the form_helper() functions. I have written the following set of code blocks, I always comment my practices so it would be easy for me to share to you guys if I get stuck on something.

Can you please tell me my fault? My instinct tells me I am following the User Guide correctly, but my mind tells me I am doing something wrong, but I can't pinpoint where it is.

Too much chatter, here's my MVC. (I don't use a database yet so I don't have a Model.)

View
Code:
<!DOCTYPE HTML>

&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Styling a Contact Form&lt;/title&gt;
        &lt;link href="css/style.css" type="text/css" rel="stylesheet" media="screen" /&gt;
    &lt;/head&gt;
    &lt;body&gt;
        <h1>Styling a Contact Form</h1>
        <h2>The Default Style</h2>
        <p>
            &lt;!--Define form attributes--&gt;
            &lt;?php
                # attributes for form_open();
                $form_attr = array (
                    'name'          => 'form',
                    'id'            => 'form',
                    'method'        => 'post'
                );
            
                # attributes for username field;
                $input_name = array (
                    'name'          => 'username',
                    'id'            => 'username',
                    'placeholder'   => 'Name',
                );
                
                # attributes for email field;
                $input_email = array (
                    'name'          => 'email',
                    'id'            => 'email',
                    'placeholder'   => 'Email Address'
                );
                
                # attributes for textarea;
                $input_message = array (
                    'name'          => 'message',
                    'id'            => 'message',
                    'placeholder'   => 'Type your message here'
                );
                
                # attributes for submit button;
                $input_submit = array (
                    'name'          => 'contact_submit',
                    'value'         => 'Send'
                );
            ?&gt;
            
            &lt;!--START Render the form--&gt;
            &lt;?php
            echo form_open('home_controller/hello_world', $form_attr);
                echo '<p>' . form_input($input_name) . '</p>';
                echo '<p>' . form_input($input_email) . '</p>';
                echo '<p>' . form_textarea($input_name) . '</p>';
                echo '<p>' . form_submit() . '</p>';
            echo form_close();
            ?&gt;
            &lt;!--END Render the form--&gt;
        </p>
    &lt;/body&gt;
&lt;/html&gt;

Controller
Code:
class Home_controller extends CI_Controller {
    
    function index () {
        $this->load->view('home_view');
    }
    
    function hello_world () {
        echo 'Your message has been sent. We\'ll get back to you soon.';
    }
    
}

Result
Styling a Contact Form
The Default Style
Code:
Fatal error: Call to undefined function form_open() in C:\xampp\htdocs\ci_formdesign\application\views\home_view.php on line 43

There you go, critics are very welcome to express their thoughts! :-P


NEWBIE ALERT! - Basic Form: Please help me find my fault - El Forum - 06-20-2011

[eluser]John Lopez[/eluser]
I GOT THE SOLUTION

Sorry about this guys, the only thing i forgot is loading the form helper itself.


NEWBIE ALERT! - Basic Form: Please help me find my fault - El Forum - 06-20-2011

[eluser]Aken[/eluser]
You need to load most helpers prior to using them! Add this to any controller method that utilizes the helper:
Code:
$this->load->helper('form');
You also didn't include your $input_submit variable into the form_submit() helper, just FYI. Smile


NEWBIE ALERT! - Basic Form: Please help me find my fault - El Forum - 06-20-2011

[eluser]InsiteFX[/eluser]
You also have this wrong!
Code:
echo '<p>' . form_textarea($input_name) . '</p>';

// should be
echo '<p>' . form_textarea($input_message) . '</p>';



NEWBIE ALERT! - Basic Form: Please help me find my fault - El Forum - 06-21-2011

[eluser]John Lopez[/eluser]
Thanks guys! I have it working already... It was all a mix up of careless placement of code and a short span of patience.. haha! :-P