in controller
if($this->email->send())
{
$this->session->keep_flashdata("msg", "<div class='alert alert-error' style='background: rgba(22, 111, 24, 0.84); color: #fff;'>
<button class='close' data-dismiss='alert'>×</button>
<strong>Sucess..!</strong> We sent a activation link to " .$email. ". Please Activate your account.
</div>");
redirect('Home/clients');
}
in veiw
<?php
if($this->session->flashdata("msg"))
{
echo $this->session->flashdata("msg");
}
?>
but after redirecting flashdata is not printing any msg.
please help me
thanks in advance
Instead of $this->session->keep_flashdata use $this->session->set_flashdata
Also don't forget to load library
$this->load->library('session');
$this->load->helper('url');
Related
Hello everyone,
I am a newbie to Magento. I want to learn **ajax process in Magento.** Can anyone help me to understand ajax in Magento with one simple example?
Your help will be highly appreciated.
I give you a simple example for you. To work with basic jQuery Ajax in Magento you have work in phtml page and Controller.
Just add the script in phtml page:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".like-result").click(function() {
//alert(this.id);
var id = this.id;
//alert(custid);
jQuery(".notify-status").hide();
jQuery(".notify-loader").show();
jQuery.ajax({
type: "POST",
data: 'pid=' + id,
url:'http://192.168.2.3/subhranil-demo/blog/index/likecount',
success:function(response){
if (response) {
jQuery(".notify-loader").hide();
jQuery(".notify-status").show();
jQuery("#un"+id).html(response);
}
}
});
});
});
</script>
In the above script under jQuery.ajax you can also see type, data, url. type is used for sending process like POST or GET; in data, you will send information to the controller; in URL, you can declare the controller path. Here I have a 'blog' module and I write the public function under 'index' controller and I give the function name 'likecount'. Also here my base path is http://192.168.2.3/subhranil-demo/. So I add the link to URL as following structure: http://192.168.2.3/subhranil-demo/blog/index/likecount.
Now I go to 'IndexController.php' in my controller's folder of blog module and open it. Under the class I add the following function:
public function likecountAction()
{
$blogload = Mage::getModel('blog/blog')->load($_POST['pid']);
$newid = $blogload['like']+1;
$data = array('like'=> $newid);
$blogload->addData($data);
try {
$blogload->setId($_POST['pid'])->save();
echo $newid;
} catch (Exception $e){
echo $e->getMessage();
}
}
Here in the Blog Database, I have the fields like pid (as a primary key) and like. the function works like that when you click on 'like-result' class the like increase +1.
My div structure also like that:
<?php
$allCollection=Mage::getModel("blog/blog")->getCollection();
$allCollection->addFieldToFilter('status',1);
if ($allCollection->count() >= 1)
{
$news = array();
?>
<div class="blog clearfix">
<?php
foreach ($allCollection as $news)
{?>
<p class="like-result" id="<?php echo $news->getId(); ?>"> <?php echo $news->getLike(); ?> </p>
<a style="display: none;" class="notify-loader"><img src="http://www.sendhersomething.com/skin/frontend/megatron/default/images/ajax/notify-loader.gif"></a>
<a style="display: none;" class="notify-status"><img src="http://www.sendhersomething.com/skin/frontend/megatron/default/images/ajax/ststus.png"></a>
<?php } ?>
</div>
<?php } ?>
Try this!
im making currently making my thesis about a record management of our university secretary.. in which all papers inside the office will be scanned and uploaded in the system.. i am using codeigniter..one of the feature in my system is to view the pdf file in other window of the browser. but my problem is, when i click the title. only blank page will be displayed in the other tab.. can you help me solve this one?? here is my code
controller:
function viewMinutesFile(){
if(isset($_GET['id'])){
$id = $_GET['id'];
$file = $this->minutes_model->getFile($id);
$fp= fopen($file->path, "r");
header("Cache-Control: maxage=1");
header("Pragma: public");
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$file->filename."");
header("Content-Description: PHP Generated Data");
header("Content-Transfer-Encoding: binary");
header('Content-Length:' .filesize($file->path));
ob_clean();
flush();
while (!feof($fp)){
$buff = fread($fp,1024);
print $buff;
}
exit;
}
}
code to open the file: this is my syntax to be clicked by the user so that pdf file will be open in the new tab
File
index.php/admin/viewMinutesFile?
id=" target="_tab">
try this one with a static url. no need any extra words for that.
Show My Pdf
New Update
if its work for you then fetch pdf name from database and put the name in the view like
Show My Pdf
now in the controller
$this->load->helper('download');
if($this->uri->segment(3))
{
$data = file_get_contents('./file_path/'.$this->uri->segment(3));
}
$name = $this->uri->segment(3);
force_download($name, $data);
well, you could add a link to file with target="_blank", like
<a href="<?php echo base_url(). 'your_controller/viewMinutesFile'; ?>" target="_blank">
View Pdf
</a>
and in controller function:
function viewMinutesFile(){
....
$file = $this->minutes_model->getFile($id);
$this->output
->set_content_type('application/pdf')
->set_output(file_get_contents($your_pdf_file));
}
you can try this on your view :
Filename
and on your controller, you can try this, because this is works for me :
function viewfile(){
$fname = $this->uri->segment(3);
$tofile= realpath("uploaddir/".$fname);
header('Content-Type: application/pdf');
readfile($tofile);
}
hope this might help you...
Just create a link to a blank page and use this code in your controller:
public function myPdfPage(){
$url = base_url('assets/your.pdf');
$html = '<iframe src="'.$url.'" style="border:none; width: 100%; height: 100%"></iframe>';
echo $html;
}
Enjoy!
There is no any problem with your code you can open easily on next tab, like other pages only difference you have to change header description and it is make sure on your browser pdf reader add-ons are available, otherwise it will give you option to download.
You may just follow this.
<?php echo form_open_multipart('your_controller/your_function','target="_blank"') ;?>
//other input fields
<?php form_close();?>
how can I check if there is a message in the message queue? for example how can I do something like :
<script type="text/javascript">
var message='<jdoc:include type="message" />'
if(message!="")
{
alert(message);
}
</script>
I am using joomla 2.5.
Thank you
So, the problem is really needing to strip the HTML from the message variable. Several things to note:
Joomla! could be returning multiple messages.
Alert are a blocking event for browsers... do you really want to do that?
First up you could place the messages in a JSON block by using some basic PHP.
<?php
$jAp = JFactory::getApplication();
$messagesJSON = json_encode($jAp->getMessageQueue());
?>
Then later in your template you could echo the messages JSON array into your Javascript similar to your original attempt.
<script type="text/javascript">
var messageJSON = <?php echo $messagesJSON; ?>
... then loop through the JSON block
This way you end up with just the text and type of the message and not the particular formatting of the current style/override.
i could not understand your question but you can get msg queue like this
$mainframe= JFactory::getApplication();
$messages = $mainframe->getMessageQueue();
if (is_array($messages)) {
echo '<ul id="system-messages">';
foreach($messages as $msg) {
echo '<li class="' . $msg['type'] . '">' . $msg['message'] . '</li>';
}
echo '</ul>';
}
Just trying to set up an AJAX contact form in Codeigniter. It's my first time using CI.
I had it working, and now it's broke and I'm not sure why.
Here is the code..
The JS
$.ajax({
type:'POST',
url: post_url,
data: post_data,
beforeSend:function(){
alert(this.data); <<< This is alerting the correct form data to me
},
success:function(msg){
$($form).fadeOut(500, function(){
var msg = '<div class="messageSent"><p>'+ msg +'</p></div>';
$form.html(msg).fadeIn(); <<< This is returning undefined
});
}
});
.. and the PHP ...
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Email extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->library('email');
}
public function index(){
$emailFromName = $this->input->post('name', TRUE);
$emailFromAddress = html_entity_decode($this->input->post('email', TRUE));
$emailFromMessage = "Email from the Brewer's website\n";
$emailFromMessage .= "==============================\n";
$emailFromMessage .= "From: " + $emailFromName + "\n";
$emailFromMessage .= "==============================\n";
$emailFromMessage .= "Respond Email; " + $emailFromAddress +"\n";
$emailFromMessage .= "==============================\n";
$emailFromMessage .= $this->input->post('message', TRUE);
$this->email->from($emailFromName);
$this->email->to('recipient#gmail.com');
$this->email->subject('Message from the website.');
$this->email->message($emailFromMessage);
$this->email->send();
echo $this->email->print_debugger(); // echoes undefined
// echo($emailFromName); // also echoes undefined
}
}
?>
I think the problem must be in the PHP.. it just doesn't seem to be reading any of the posted variables. I cant even echo $this->input->post('name'); (Although I had it working!)
.. so what am I doing wrong?
NOTE - I put the html_entity_decode in there because I noticed the email addy was getting posted as "address%40gmail.com"... so it seemed like a good idea. Is it necessary?
Strictly speaking, this is not an answer for your question- but I struggled greatly with stabilizing my CodeIgniter project's mail feature. The solution I found took about 1 hour to implement, and it has saved me 10 hours of trouble, I'm sure.
Consider sending mail from your application with the "SwiftMailer" framework. It is a powerful reliable php mail framework, and it's free. At first I had a hard time integrating the 2 frameworks, then I found this blog, I had the task done in minutes.
http://grafikkaos.co.uk/blog/article/101-using-swift-mailer-with-codeigniter
I am trying to implement recaptcha my form in CodeIgniter (without using the recaptcha library). This works fine, however as in my form, I am displaying each fields errors individually, I want to display recaptcha error next to its place in the form, can someone help me how can i do it?
The code from my controller:
$this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|max_length[25]');
$this->form_validation->set_rules('email', 'Email address', 'trim|required|valid_email');
//With above set_rules i'm able to display each fields errors next to it,
//How can i display following recaptcha error next to it.
if (!$resp->is_valid)
{
//reCAPTCHA was entered incorrectly
die (
"The reCAPTCHA wasn entered incorrectly." .
"(reCAPTCHA said: " . $resp->error . ")
");
}
else
{
//Successful verification
die('Success!');
}
Thanks for any help.
If you aren't running the recaptcha field through the form validation library you won't be able to use the form_error() function, but you can easily send the error to your view as a variable:
if ($this->form_validation->run())
{
if ( ! $resp->is_valid)
{
$data['recaptcha_error'] = "reCAPTCHA said: ".$resp->error;
}
else
{
// Process form
}
}
$this->load->view('my_view', $data);
Then in your view (wherever/however you want):
<?php if (isset($recaptcha_error)): ?>
<label class="error">
<?php echo $recaptcha_error; ?>
</label>
<?php endif; ?>