Welcome Guest, Not a member yet? Register   Sign In
CI+Smarty form_validation. Please help
#1

[eluser]prashid[/eluser]
Hi,

Before posting here googled alot and searched all the threads of CI forums but couldn't find any example to achieve this. Only found this thread

http://ellislab.com/forums/viewthread/137440/#677741

I have 2 questions
1 - How to use CI form_validation in smarty template. Like showing errors.
2 - How to use language in templates for smarty.

Like in CI views we use
Code:
<?php echo lang('usernamelabel');?>
<?php echo form_error('username')?>
&lt;?php echo validation_errors('<p class="mainerror">'); ?&gt;

CI+Smarty is working fine. Now I want to implement above 2 things.

Please help
#2

[eluser]prashid[/eluser]
Anyone please
#3

[eluser]Vheissu[/eluser]
[quote author="prashid" date="1285219004"]Anyone please[/quote]

Although I don't use Smarty, I use Dwoo I think the following should work for you. Try encasing the CI function calls inside of these brackets: "{}" as you do everything else in Smarty.

Code:
{form_error('username')}

So you're basically replacing the opening / closing PHP tags with the curly braces, and in cases where you are echoing, you the curly braces in Smarty will automatically echo your content.
#4

[eluser]prashid[/eluser]
I will try that.
Do you think form_error will be available in smarty template?
Any idea on using language?

Thanks
#5

[eluser]Vheissu[/eluser]
[quote author="prashid" date="1285228607"]I will try that.
Do you think form_error will be available in smarty template?
Any idea on using language?

Thanks[/quote]

Only one way to find out, try it. I use Dwoo and it works for me, calling Ci functions inside of template files that is. If the above doesn't work in Smarty, pass the CI instance to the view and use it.

Example:
Code:
$data['ci'] = &get;_instance();

Then pass through the variable you stored the CI instance inside of, then you should be able to call any CI function in template files like so:

Code:
$ci->form_validation()->form_error();

You can call any part of CI using it that way. So if the first solution doesn't work, use this second solution which will work.
#6

[eluser]prashid[/eluser]
Thanks for the help. I will try both approaches and get back to you.
#7

[eluser]prashid[/eluser]
[quote author="Vheissu" date="1285230656"]
Code:
$data['ci'] = &get;_instance();
[/quote]

Thanks. Most of the things are working. One more question.
How do I access FORM elements like

{$ci->???->form_input($username)}

Passing ci by instance, Do you think its the right approach?. Page won't be heavy in loading for something?

Thanks again




Theme © iAndrew 2016 - Forum software by © MyBB