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