Welcome Guest, Not a member yet? Register   Sign In
[newbee] code outputs only html
#1

[eluser]Rokit[/eluser]
Hello,

I'm new with Codeigniter.
I start to make a simple form just like this:

Code:
<?=$this->validation->error_string; ?>

<?=form_open('form'); ?>
    <b>Titel van dit album</b><br />
    &lt;input type="text" name="titel_album" value="" /&gt;<br /><br />
    &lt;input type="submit" name="toevoegen" value="Album toevoegen" /&gt;    
&lt;/form&gt;

When i call this page, the php don't work here i think
This is my output on the screen

validation->error_string; ?&gt; Titel van dit album
+ inputfield and a button

And the source code
&lt;?php=$this->validation->error_string; ?&gt;

&lt;?php=form_open('form'); ?&gt;
<b>Titel van dit album</b><br />
&lt;input type="text" name="titel_album" value="" /&gt;<br /><br />
&lt;input type="submit" name="toevoegen" value="Album toevoegen" /&gt;

&lt;/form&gt;

I use php5 (wampserver) on a windows xp machine.

someone can help me?

Thanks
#2

[eluser]gtech[/eluser]
use

&lt;?php ... ?&gt;

instead of


&lt;?= ... ?&gt;

is only used to echo variables

&lt;?=$var?&gt;

its like doing

&lt;?php echo $var; ?&gt;

I assume you are calling your code through the controller. hope it helps unless I am on the wrong track.

[edit]dang! must think before replying! gunters below reply is correct as you can echo form_open(<path>); if short tags are disabled only the &lt;?php open tag will work[/edit]
#3

[eluser]gunter[/eluser]
is the short_open_tag option in your php.ini on or off? Smile
edit: because it´s switched off by default...
#4

[eluser]TheFuzzy0ne[/eluser]
[quote author="gtech" date="1209161031"]use

&lt;?php ... ?&gt;

instead of


&lt;?= ... ?&gt;

is only used to echo variables

&lt;?=$var?&gt;

its like doing

&lt;?php echo $var; ?&gt;

I assume you are calling your code through the controller. hope it helps unless I am on the wrong track.[/quote]

Using the short tags without the "=" sign should work too. But using the full tags is clearer (although slightly more cluttered), and is probably best in case your server supports any other scripting languages.

e.g

Code:
&lt;?somefunction();?&gt;
#5

[eluser]gtech[/eluser]
[quote author="Codeigniter User Guide" date="1209164208"]
Automatic Short Tag Support

Note: If you find that the syntax described in this page does not work on your server it might be that "short tags" are disabled in your PHP ini file. CodeIgniter will optionally rewrite short tags on-the-fly, allowing you to use that syntax even if your server doesn't support it. This feature can be enabled in your config/config.php file.

Please note that if you do use this feature, if PHP errors are encountered in your view files, the error message and line number will not be accurately shown. Instead, all errors will be shown as eval() errors.
Alternative Echos

Normally to echo, or print out a variable you would do this:
&lt;?php echo $variable; ?&gt;

With the alternative syntax you can instead do it this way:
&lt;?=$variable?&gt;
[/quote]

here is the CI documentation extract to save any confusion I may of caused.. apologies.
#6

[eluser]Rokit[/eluser]
I did try this &lt;?php function... but still no output.

Form
Code:
&lt;?php $this->validation->error_string; ?&gt;

&lt;?php form_open('form'); ?&gt;
    <b>Titel van dit album</b><br />
    &lt;input type="text" name="titel_album" value="" /&gt;<br /><br />
    &lt;input type="submit" name="toevoegen" value="Album toevoegen" /&gt;
    
&lt;/form&gt;

The controller
Quote:class Pictures extends Controller {

function index(){
-
$this->load->helper(array('form', 'url'));

$this->load->library('validation');

$rules['titel_album'] = "required";


$this->validation->set_rules($rules);

if ($this->validation->run() == FALSE)
{
$this->load->view('pictures/addalbum');
}
else
{
$this->load->view('formsuccess');
}

}

}

Html source
Code:
<b>Titel van dit album</b><br />
    &lt;input type="text" name="titel_album" value="" /&gt;<br /><br />
    &lt;input type="submit" name="toevoegen" value="Album toevoegen" /&gt;
    
&lt;/form&gt;

- When i look at the source i see also no form open tags (<form method=...)
- When i submit the form (empty field) i get no error
#7

[eluser]gunter[/eluser]
now you have to echo it!
Code:
&lt;?php echo $this->validation->error_string; ?&gt;
&lt;?php echo form_open('form'); ?&gt;
or you set the parameter in the php.ini an use the short tag version...
#8

[eluser]TheFuzzy0ne[/eluser]
[quote author="Rokit" date="1209167596"]I did try this &lt;?php function... but still no output.

Form
Code:
&lt;?php $this->validation->error_string; ?&gt;

&lt;?php form_open('form'); ?&gt;
    <b>Titel van dit album</b><br />
    &lt;input type="text" name="titel_album" value="" /&gt;<br /><br />
    &lt;input type="submit" name="toevoegen" value="Album toevoegen" /&gt;
    
&lt;/form&gt;

The controller
Quote:class Pictures extends Controller {

function index(){
-
$this->load->helper(array('form', 'url'));

$this->load->library('validation');

$rules['titel_album'] = "required";


$this->validation->set_rules($rules);

if ($this->validation->run() == FALSE)
{
$this->load->view('pictures/addalbum');
}
else
{
$this->load->view('formsuccess');
}

}

}

Html source
Code:
<b>Titel van dit album</b><br />
    &lt;input type="text" name="titel_album" value="" /&gt;<br /><br />
    &lt;input type="submit" name="toevoegen" value="Album toevoegen" /&gt;
    
&lt;/form&gt;

- When i look at the source i see also no form open tags (&lt;form method=...)
- When i submit the form (empty field) i get no error[/quote]

The most likely reason you aren't getting the error string is that your first line of code appears to be missing an "echo".

try:

Code:
&lt;?php echo $this-&gt;validation->error_string; ?&gt;

&lt;?php form_open('form'); ?&gt;
    <b>Titel van dit album</b><br />
    &lt;input type="text" name="titel_album" value="" /&gt;<br /><br />
    &lt;input type="submit" name="toevoegen" value="Album toevoegen" /&gt;
    
&lt;/form&gt;

With a bit of luck that might fix your problem, (although it does appear completely unrelated).
#9

[eluser]TheFuzzy0ne[/eluser]
[quote author="gunter" date="1209167892"]now you have to echo it!
Code:
&lt;?php echo $this->validation->error_string; ?&gt;
&lt;?php echo form_open('form'); ?&gt;
or you set the parameter in the php.ini an use the short tag version...[/quote]

Sweet! I didn't know that you had to echo form_open().

I'll have to remember that as I will no doubt make the same mistake.

Edit: Now I think about it, it only makes sense that you need to echo form_open(). After all, controllers shouldn't output any code, only return values when necessary.
#10

[eluser]Rokit[/eluser]
[quote author="gunter" date="1209167892"]now you have to echo it!
Code:
&lt;?php echo $this->validation->error_string; ?&gt;
&lt;?php echo form_open('form'); ?&gt;
or you set the parameter in the php.ini an use the short tag version...[/quote]

Thanks Big GrinBig Grin
It works :coolsmile:




Theme © iAndrew 2016 - Forum software by © MyBB