Twitter bootstrap how to hide error message on initialization? - php

I have simple alert message which should show up only when there is error. However I don't know how to hide message on initialization. If I manually hide the message then error message stays hidden even when there is error.
<div class="alert alert-error">
<button class="close" data-dismiss="alert" type="button">×</button>
<?php echo $error?>
</div>

Try this
<?php if(isset($error)): ?><div class="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<?php echo $error; ?>
</div>
<?php endif; ?>
make sure that you include bootstrap.js and jquery.js correctly

Related

Add a popup in a custom php webapp

I need to add a popup to the following web app
https://github.com/gunet/openeclass/tree/3.12.x
I have tried to put my code to many files by trial and error but no luck.
Could someone tell me if below code is the appropriate way to do this and in which file should i put it so it shows up in the first page?
https://openeclass.panteion.gr/
<?php
// PHP program to pop an alert
// message box on the screen
// Display the alert box
echo '<script>alert("Welcome to our site")</script>';
?>
As suggested i plan to use the following. Where should i put it and how should i combine it with a cookie so that it is shown only once to each user?
<div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
You should not use JavaScript "alert()" function to show some messages to the users. It is an ugly way to do such thing and it is mostly used for old school debugging helper.
In my opinion you can trigger a popover or an alert (see Bootstrap 3 documentation) in $(document).ready(function () { ... } section within template/default/js/main.js. But this would show the message to your visitors every time they open any page. That is why you should show the message only once and remember it in a Cookie variable such as "messageShown=true". In the section which I mentioned above you should check like if(Cookies.messageShown=='false') before you trigger the alert message.

Div css style load before the error in CodeIgniter

I am facing a problem which in my code the error div loads earlier before it shows the error . could someone please help me to fix that
this is my view file
<div class="alert alert-danger mg-b-0" role="alert">
<?php echo form_error('index'); ?>
<?php
if(isset($error)){
echo 'Your Index number is not registered with our system[enter image description here][1]' .
'<br />'.'Click here to Register'.
'<br />';
}else{
'<br />';
}
?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
here is the screenshot of this
you already printed the alert before the check so if there is no $error it will already show an empty alert, you have to check first then echo your whole divs inside:
<?php if (isset($error)): ?>
<div class="alert alert-danger" role="alert">
<?php echo $error ?> <!-- or write whatever you want -->
</div>
<?php endif ?>

Laravel redirect with session message does not always persist to my request

I have an Admin tool built with Laravel where users can perform certain actions on individual records.
The way the code is built I am performing a post to a URL, executing the necessary code, updating the database and then redirecting back with a session message.
Controller Code:
return Redirect::back()->with("msg_success", "SMS has been sent!");
Now the page that gets rendered from the redirect has a check at the top to display the session message if it exists.
View Code:
#if (Session::has('msg_success'))
<div class="col-lg-10">
<div role="alert" class="alert alert-success alert-dismissible fade in">
<button aria-label="Close" data-dismiss="alert" class="close" type="button"><span aria-hidden="true">×</span></button>
<strong>Success! </strong>{{ Session::get('msg_success') }}
</div>
</div>
<div class="clearfix"></div>
#endif
For some reason, sometimes the message is displayed and other times it is not. I cant for the life of me figure out why. Could it be middle ware that is intercepting the request and then performing another request and it is getting destroyed? I do not see anything in there that looks like it would cause this.
Any ideas would help. I thought about using a URL parameter when redirecting like
return Redirect::to('explicitURL?success=whateverthesuccesmessageis')
But I would prefer not do this as my action is shared among different URL's.
In your controller add this:
Session::flash('msg_success', 'SMS has been sent!')
return Redirect::back();
And in the View:
#if (Session::has('msg_success'))
<div class="col-lg-10">
<div role="alert" class="alert alert-success alert-dismissible fade in">
<button aria-label="Close" data-dismiss="alert" class="close" type="button"><span aria-hidden="true">×</span></button>
<strong>Success! </strong>{{ Session::get('msg_success') }}
</div>
</div>
<div class="clearfix"></div>
#endif

Laravel 4 Redirect with global styling

Does anyone know where and how to style the redirect with global such as:
return Redirect::route('home')
->with('global', 'Your content has been posted!');
I want to use the bootstrap alerts with the global message
I just needed to put the styling after the global
Here is what I did:
return Redirect::route('admin-console-post')
->with('global', '
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
Your content has been posted successfully!
</div>
');
You need to style it in view like this:
#if(Session::has('global'))
<div class="output">
{{ Session::get('global') }}
</div>
#endif
Where output is class in which you put style of your choice.
Hope it helps ^^.

Using Language Class in Controller (CodeIgniter)

First of all, I made research but couldn't find anything about it.
I'm sending flash data to users when they update or add something. My controller file's related part is like this;
function hizmet_ekle()
{
if($this->mhizmetler->hizmet_ekle())
{
$this->session->set_flashdata('ok', 'hizmet sisteme eklendi!');
redirect('panel/hizmetler');
}
else
{
$this->session->set_flashdata('hata', 'Bir hata oluştu. Lütfen tekrar deneyin!');
redirect('panel/hizmetler');
}
}
And my view's related parts are like this;
<?php if($this->session->flashdata('ok')): ?>
<div class="alert alert-success fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-check"></i> <?php echo $this->session->flashdata('ok');?>
</div>
<?php endif; if($this->session->flashdata('hata')): ?>
<div class="alert alert-danger fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-times"></i> <?php echo $this->session->flashdata('hata');?>
</div>
<?php endif; echo validation_errors('
<div class="alert alert-danger fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-times"></i> ', '
</div>'); ?>
My system has a few different languages, it means I have to send different notification messages(session flashdata's) for each language but I can't use lang key in my controller file. How can I handle it?
Thanks in advance.
I found it!
I have to use it like this;
$this->session->set_flashdata('ok', $this->lang->line("greek"));

Categories