[newbee] code outputs only html - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [newbee] code outputs only html (/showthread.php?tid=7872) Pages:
1
2
|
[newbee] code outputs only html - El Forum - 04-25-2008 [eluser]Rokit[/eluser] Hello, I'm new with Codeigniter. I start to make a simple form just like this: Code: <?=$this->validation->error_string; ?> When i call this page, the php don't work here i think This is my output on the screen validation->error_string; ?> Titel van dit album + inputfield and a button And the source code <?php=$this->validation->error_string; ?> <?php=form_open('form'); ?> <b>Titel van dit album</b><br /> <input type="text" name="titel_album" value="" /><br /><br /> <input type="submit" name="toevoegen" value="Album toevoegen" /> </form> I use php5 (wampserver) on a windows xp machine. someone can help me? Thanks [newbee] code outputs only html - El Forum - 04-25-2008 [eluser]gtech[/eluser] use <?php ... ?> instead of <?= ... ?> is only used to echo variables <?=$var?> its like doing <?php echo $var; ?> 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 <?php open tag will work[/edit] [newbee] code outputs only html - El Forum - 04-25-2008 [eluser]gunter[/eluser] is the short_open_tag option in your php.ini on or off? edit: because it´s switched off by default... [newbee] code outputs only html - El Forum - 04-25-2008 [eluser]TheFuzzy0ne[/eluser] [quote author="gtech" date="1209161031"]use <?php ... ?> instead of <?= ... ?> is only used to echo variables <?=$var?> its like doing <?php echo $var; ?> 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: <?somefunction();?> [newbee] code outputs only html - El Forum - 04-25-2008 [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: <?php echo $variable; ?> With the alternative syntax you can instead do it this way: <?=$variable?> [/quote] here is the CI documentation extract to save any confusion I may of caused.. apologies. [newbee] code outputs only html - El Forum - 04-25-2008 [eluser]Rokit[/eluser] I did try this <?php function... but still no output. Form Code: <?php $this->validation->error_string; ?> The controller Quote:class Pictures extends Controller { Html source Code: <b>Titel van dit album</b><br /> - 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 [newbee] code outputs only html - El Forum - 04-25-2008 [eluser]gunter[/eluser] now you have to echo it! Code: <?php echo $this->validation->error_string; ?> [newbee] code outputs only html - El Forum - 04-25-2008 [eluser]TheFuzzy0ne[/eluser] [quote author="Rokit" date="1209167596"]I did try this <?php function... but still no output. Form Code: <?php $this->validation->error_string; ?> The controller Quote:class Pictures extends Controller { Html source Code: <b>Titel van dit album</b><br /> - 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[/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: <?php echo $this->validation->error_string; ?> With a bit of luck that might fix your problem, (although it does appear completely unrelated). [newbee] code outputs only html - El Forum - 04-25-2008 [eluser]TheFuzzy0ne[/eluser] [quote author="gunter" date="1209167892"]now you have to echo it! Code: <?php echo $this->validation->error_string; ?> 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. [newbee] code outputs only html - El Forum - 04-25-2008 [eluser]Rokit[/eluser] [quote author="gunter" date="1209167892"]now you have to echo it! Code: <?php echo $this->validation->error_string; ?> Thanks It works :coolsmile: |