Welcome Guest, Not a member yet? Register   Sign In
form_open helper function not working
#1

[eluser]01010011[/eluser]
Hi,
I am following the CI tutorial called "Creating a blog in 20 minutes" and the "submit" button on my comment_view page does not work. (When I click the button it is supposed to take me to a 404 error page, but nothing happens)

I noticed that when the presenter of the tutorial views his page source, he gets this ():
Code:
<html>
<head>
<title><?php echo $title; ?> </title>
</head>
<body>
<h1>&lt;?php echo $heading; ?&gt;</h1>

&lt;form method="post" action="http://www.example.com/CodeIgniter/index.php/blog/comment_insert
&lt;input type="hidden" name="entry_id" value="1" />

&lt;?php form_open('blog/comment_insert'); ?&gt;

&lt;?php form_hidden('entry_id', $this->uri->segment(3)); ?&gt;

<p>&lt;textarea name= "body" rows="10"&gt;&lt;/textarea></p>
<p>&lt;input type="text" name = "author" /&gt;&lt;/p>
<p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

But when I view my source code, I did not get these lines:

Code:
&lt;form method="post" action="http://www.example.com/CodeIgniter/index.php/blog/comment_insert
&lt;input type="hidden" name="entry_id" value="1" />

So I was wondering whether my form helper functions were working? I've included these helpers in the constructor as instructed:
Code:
$this->load->helper('url');
$this->load->helper('form');

So what is the problem?
#2

[eluser]Kindari[/eluser]
If you include this code in your source:
Code:
&lt;?php form_open('blog/comment_insert'); ?&gt;

&lt;?php form_hidden('entry_id', $this->uri->segment(3)); ?&gt;

it will output:

Code:
&lt;form method="post" action="http://www.example.com/CodeIgniter/index.php/blog/comment_insert
&lt;input type="hidden" name="entry_id" value="1" />


If you need further help, post the source code you are actually using, not what you see in his tutorial.
#3

[eluser]tomdelonge[/eluser]
You have to "echo" it.

Use:

Code:
&lt;?php echo form_open();?&gt;

I think that's all you need.
#4

[eluser]mddd[/eluser]
Or use '&lt;?=' which is the same as '&lt;?php' and 'echo' put together.
&lt;?=form_open();?&gt;
#5

[eluser]adamp1[/eluser]
Err you havn't closed the closing tag on the &lt;form&gt; open tag??

You have
Code:
&lt;form method="post" action="http://www.example.com/CodeIgniter/index.php/blog/comment_insert

You want
Code:
&lt;?php print form_open('blog/comment_insert');?&gt;
#6

[eluser]01010011[/eluser]
[quote author="tomdelonge" date="1271226570"]You have to "echo" it.
Use:
Code:
&lt;?php echo form_open();?&gt;
I think that's all you need.[/quote]

Thank you very much tomdelonge. You were right, it works now because I forgot to use echo. The presenter is using the shorter form of the language and I am not (because I have not figured out how to get it to work).


[quote author="mddd" date="1271245338"]Or use '&lt;?=' which is the same as '&lt;?php' and 'echo' put together.
&lt;?=form_open();?&gt;[/quote]

Thanks for your reply mddd. When I typed that, it did not work in Chrome. How do I enable this?



[quote author="adamp1" date="1271247058"]Err you havn't closed the closing tag on the &lt;form&gt; open tag??

You have
Code:
&lt;form method="post" action="http://www.example.com/CodeIgniter/index.php/blog/comment_insert

You want
Code:
&lt;?php print form_open('blog/comment_insert');?&gt;
[/quote]

Thanks adamp1, I don't know how I managed to leave that out in this post.


[quote author="Kindari" date="1271224609"]If you include this code in your source:
Code:
&lt;?php form_open('blog/comment_insert'); ?&gt;

&lt;?php form_hidden('entry_id', $this->uri->segment(3)); ?&gt;

it will output:

Code:
&lt;form method="post" action="http://www.example.com/CodeIgniter/index.php/blog/comment_insert
&lt;input type="hidden" name="entry_id" value="1" />


If you need further help, post the source code you are actually using, not what you see in his tutorial.[/quote]

Ok, Thanks Kindari
#7

[eluser]cahva[/eluser]
[quote author="01010011" date="1271260701"]Thank you very much tomdelonge. You were right, it works now because I forgot to use echo because the presenter is using the shorter form of the language and I am not (because I have not figured out how to get it to work)
[/quote]

To use short tags, you will have to enable short tags by either adding
short_open_tag On

..to php.ini or vhost.

Or enable it in config/config.php:
Code:
$config['rewrite_short_tags'] = TRUE;

Latter will work even if short tags are disabled in PHP(but works only in view files).
When enabling rewrite_short_tags and short tags are disabled from serverside, CI will use eval to the view file's code. If you have errors in view files, debugging is a little harder as it will always tell you that some error occured on line 1(if I remember right).
#8

[eluser]01010011[/eluser]
It worked, thank you very much cahva




Theme © iAndrew 2016 - Forum software by © MyBB