• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NEWBIE ALERT! - Basic Form: Please help me find my fault

[eluser]John Lopez[/eluser]
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.)


        &lt;title&gt;Styling a Contact Form&lt;/title&gt;
        &lt;link href="css/style.css" type="text/css" rel="stylesheet" media="screen" /&gt;
        <h1>Styling a Contact Form</h1>
        <h2>The Default Style</h2>
            &lt;!--Define form attributes--&gt;
                # 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'
            &lt;!--START Render the form--&gt;
            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();
            &lt;!--END Render the form--&gt;

class Home_controller extends CI_Controller {
    function index () {
    function hello_world () {
        echo 'Your message has been sent. We\'ll get back to you soon.';

Styling a Contact Form
The Default Style
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

[eluser]John Lopez[/eluser]

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

You need to load most helpers prior to using them! Add this to any controller method that utilizes the helper:
You also didn't include your $input_submit variable into the form_submit() helper, just FYI. Smile

You also have this wrong!
echo '<p>' . form_textarea($input_name) . '</p>';

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

[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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.