Smarty template question - php

i am new to smarty template and i am trying to do this.
I have a html form in the tpl file and in that form action is for a php email function email.php. I am not able to get it to work. if i have the complete code(html form + php email code) and save as a php file, it works fine.
is there any way to call the php code from email.php inside that tpl file? i am completely new and i am just making some changes on the site.
regards

after doing some google search, i found that i can do this way
In the tpl(ex - mail.tpl)
{ php }
//all php code here, in my case its the mailer
{ /php }
and in the form action, just give "mail.tpl" .
fyi, i designed this contact with ajax way to just do the submission in the same page without navigating.

{php}{/php} is deprecated in Smarty V3 now

Related

How to embed codeigniter script into external php script

l have a index file of my website in
localhost-->mywebsite-->index.php (this is my external script)
and i have build a registration form with codeigniter.
I can use the registration form using url http://localhost/codeigniter/index.php/form.
But how can i attach that registration form into my website index file.
using include_once"../codeigniter/index.php/form"; in my external php script(index.php of my website) is not working.
However if i make that 'form' the default controller file and use the following code from external php script
include_once "codeigniter/index.php"; it works well. but what if i need other controller files but not just 'form'?
Update:
I can also link to that file from external php script as:
<a href="codeigniter/index.php/form>Register</a>.
But not include. Whenever i include it displays no such file.
So if i understood you correctly you want to use codeigniter's form in some other php website, actually idea to do such thing is wrong (as you can't normally control your form action link etc better to build same for in other website directly), but answer for your question is following trick
Place this code in your other website where you want to have codeigniter form included
$output = shell_exec('php ABSOLUTE_PATH/codeigniter/index.php form index');
// where "ABSOLUTE_PATH" is absolute path to your codeigniter project
// "form" is your controller name
// "index" action name
echo $output; // will echo form html generated by codeigniter
In localhost-->mywebsite-->index.php, you could try this:
<?php include_once('/codeigniter/index.php/form'); ?>
If not you can move your index.php code into a codeigniter view and set it up that way.
try using below code...
<?php $data = file_get_contents("http://localhost/codeigniter/index.php/form/");
$html_encoded = htmlentities($data);
echo $html_encoded;
?>
In the above code we get all contents of the url in $data variable and then use htmlentities on that for html encoding...

How to Create Function Search Jquery Easy UI in controller Codeigniter

I Try tutorial from http://www.jeasyui.com/tutorial/datagrid/datagrid24.php
I create this function in mycontroller..
function doSearch(){
$('#tt').datagrid('load',{
itemid: $('#itemid').val(),
productid: $('#productid').val()
});
}
I get error message like this..
Parse error: parse error, expecting T_VARIABLE' or'$'' in C:\xampp\htdocs\ci_jquery\application\controllers\crud.php on line 55
I dont know, how to create that function in controller codeigniter.
Thanks For The Reply..
Your problem is that the code which you've posted is not PHP code, it's Javascript code (more specifically, it belongs to the jQuery framework). It does not need to live in a controller, but instead should be added to the view, where your HTML content is.
You first need to load a view file, and then add the code above into it.
$this->load->view('myview');
You would then have to add the Javascript code which you've posted into your view file (in the example I've provided, that would be in application/views/myview.php. Make sure to also include the jQuery library in your template!
You can read more on views here: http://ellislab.com/codeigniter/user-guide/general/views.html

Render js template through php using mustache

I am using mustache PHP to render my html files and everything works correctly except in one case. There is a situation where I load an html file through an ajax call following this structure:
PHP - renders -> HTML - javascript appends -> HTML 2nd file
What I would like to do is to get the mustache parameters into the HTML 2nd file, as some data is generated in the initial PHP file and I wouldn't like to make another call to retrieve this data again.
Do I need mustache js version for this ?
How can I get the data from the PHP in js by using mustache?
And how can I get the PHP rendered variables in the HTML 2nd file ?
What I can do is to insert hidden inputs to get the data from them in javascript but I would really like to avoid this practice. I don't like this practice as user can easily modify the inputs.
Any idea??
At the end I found a solution for this. Print the output of a php file on an ajax call.
Mustache_Autoloader::register();
$m = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader('./templates/')
));
echo $m->render('templatename', $o);
and then using .html(data); with jQuery

Codeigniter PHP - loading a view at an anchor point

I have a form at the bottom of a long page, if a user fills out the form but it doesn't validate the page is reloaded in the typical codeigniter fashion:
$this->load->view('template',$data);
however because the form is way down at the bottom of the page I need the page to load down there like you do with HTML anchors. Does anyone know how to do this in codeigniter?
I can't use the codeigniter
redirect();
function because it loses the object and the validation errors are gone. Other frameworks I've used like Yii you can call the redirect function like:
$this->redirect();
which solves the problem because you keep the object. I've tried using:
$this->index()
within the controller which works fine as a redirect but the validation errors are in another method which is where the current page is loaded from:
$this->item($labs)
but when I use this it get stuck in a loop
Any ideas? I've seen this question a lot on the net but no clear answers. I'm researching using codeigniter "flash data" but think it's a bit overkill.
cheers.
I can't personally vouch for this, but according to this thread if you append the anchor to the form's action, it will work.
CodeIgniter helper:
<?php echo form_open('controller/function#anchor'); ?>
Or vanilla HTML:
<form method='post' action='controller/function#anchor'>
If you were open to using Javascript, you could easily detect a $validation_failed variable and appropriately scroll. Or, even better, use AJAX.
Another option is to put the form near the top of the page?
Ok, as far as I understood your problem, it isn't much related to the back end(codeigniter). You want the form at the bottom of the page to be 'what-users-sees-on-page-load' (since you mention anchors).
Now, what you can do is, you can set delimiters for your validation error messages using:
echo validation_errors('<div id="bottom_form_error">', '</div>');
Using jQuery ScrollTo, do:
$( function() { $('#bottom_form_error').ScrollTo(); } );
And, the user will be scrolled to the errors at the bottom of the page. Don't forget to include jQuery too.
Anchor hash fragment click is different - it is scrolling at ∞ speed.
I hope that is what you wanted.
P.S. I am ignoring what you said below this line:
Does anyone know how to do this in codeigniter?
as I felt it is not really relevant to the question.

how to upload file php through jquery and smarty

i need to upload a file doc or pdf or rich text through jquery and smarty
i try to pass the file in jquery is given below
window.location.href= sitePath+'download?p='+$('#file').val();
but the p doesn't have value. how to get the file path or name and how can stored in server
in controller i write just pass the query to model is given below
$model=new download();
$id=$model->upload($param);
and i can't develop the model code....
please help me
You can't send files like that.
You should either submit a form with enctype="multipart/form-data" or use some AJAX uploader (which uses form submit to iframe and then stores a file using PHP script).
EDIT: Some references
http://www.w3schools.com/php/php_file_upload.asp - tutorial on how to upload a file using PHP
http://valums.com/ajax-upload/ - example of ajax uploader.
EDIT2: The problem is not with your model code but with the way you try to submit a file.

Categories