I have used redirect
return Redirect::to('/lk/payment_status')->with('message', 'Платеж успешно завершен’);
How display message variable message on /lk/payment_status page?
it seems you want to show some flash message after redirecting from page
if (Session::has('message')) {
$value = Session::get('message');
}
now you can use $value and show it inside your page.
you can use this to get session flash message or even you can use Flash api
Flash::sucess('some message');
// now do redirection
inside your page you can use flash tag
{% flash %}
<div class="alert alert-{{ type }}">
{{ message }}
</div>
{% endflash %}
If the payment_status page is a blade template (payment_status.blade.php) then you can easily output it using the {{ }} marking, like this -
{{ message }}
Please try
#if(session('message'))
{{session('message')}}
#endif
Related
So i'm trying to gererate a frontend user list, but i'm having trouble reaching the avatar url.
i'm able to get all user names but when i try to do the same with the profile picture the fallback is shown.
The {{ user.avatar.url }} is working on the user page when someone is signed in.
I've tried to look for the query used on the backend to get the user avatar on the preview, but i was not able to find it.
I don't know if this is relevant but i'm using https://octobercms.com/plugin/netsti-uploader for frontend users to upload their avatars. It's working since if i upload it on the frontend the backend user preview shows the right avatar
This is what i am using to get all users:
CODE:
use October\Rain\Auth\Models\User;
function onInit() {
$this['activatedUsers'] = User::whereIsActivated(true)->get();
}
MARKUP
<div>
{% for user in activatedUsers %}
<div class="card list">
{% if user.avatar %}
<img class="userimg" src="{{ user.avatar.url }}">
{% else %}
<img class="userimg" src="assets/images/user.png">
{% endif %}
<p class="name"><span class="rank-title">NAME</span><br>{{ user.name }} {{ user.surname }}</p>
{% if user.last_login %}
<p><span class="rank-title">LAST UPDATE</span><br>{{ user.last_login }}</p>
{%endif%}
</div>
{% endfor %}
All help is appreciated, thanks
try to use it like that.
use RainLab\User\Models\User;
function onInit() {
$this['activatedUsers'] = User::whereIsActivated(true)->get();
}
Markup
{% for user in activatedUsers %}
<div class="card list">
{{ user.avatar.path }}
</div>
{% endfor %}
Have a look at October\Rain\Database\Attach\File class to see available methods :
getThumb($w,$h,$options) - Generates and returns a thumbnail path
getPath() - Returns the public address to access the file
getLocalPath() - Returns a local path to this file. If the file is stored remotely,it will be downloaded to a temporary directory.
getDiskPath() - Returns the path to the file, relative to the storage disk
e.g :
{{user.avatar.getThumb(200,200, { mode : 'crop' } )}}
install "Frontend File Uploader for Model" plugin
insert {% component 'imageUploader' %} in your markup
insert
function onInit()
{
$user = Auth::getUser();
if($user){
$component = $this->addComponent(
'NetSTI\Uploader\Components\ImageUploader',
'imageUploader',
['modelClass'=>'RainLab\User\Models\User','modelKeyColumn'=>'avatar', 'deferredBinding' => false]
);
$component->bindModel('avatar', $user);
}
}
on your code section
You can query the backend user model with with 'avatar'.
use Backend\Models\User;
...
$user = User::where('id', $author_id)->with('avatar')->first();
...
<h1>{{ user.avatar.path }}</h1>
I want to show a success message once the email is sent after redirected to same page. Here is my code :
return redirect('currentshowreport?showid='.$show_id)->with('success','Email sent successfully');
I am getting redirected to the specified page but the success message is not getting displayed. How to achieve this?
Try this:
#if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
#endif
I have a route post called "postContact" and when the post is success I redirect to the same contact.blade.php where place the post:
<form action="{{ route('post_contact) }}"></form>
I want to see a msg if the post have success, but the Input::get('some data') not working to me.
this is my controller resume:
public function postContact($params) {
//if successful
$msg_params = array(
'msg_type' => 'success',
'msg_text' => 'my text to show',
);
return redirect()->back()->withInput($msg_params);
}
But in the contact.blade.php this not working:
#if(isset($msg_type))
<div class="alert">{{ $msg_text }}</div>
#endif
The variables not exits...
I don´t want use flash data here, because contact.blade is a module of another external app laravel and can't share sessions.
What is happening here?
Because doing a redirect, those variables are set in session. So you may try:
#if(Session::has('msg_type'))
<div class="alert">{{ Session::get('msg_text') }}</div>
#endif
If you don't want to use session variables, then you can use route parameters. You can get the parameters using the Request facade:
#if(Request::has('msg_type'))
<div class="alert">{{ Request::get('msg_text') }}</div>
#endif
If you're redirecting back to the page, Laravel will store the data in the Session. So you need to enter this to show the data:
#if(Session::has('msg_type'))
<div class="alert">
{{ Session::get('msg_text') }}
</div>
#endif
Hope this works!
Controller
return redirect()->back()->with('success', ['your message,here']);
Blade:
#if (\Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{!! \Session::get('success') !!}</li>
</ul>
</div>
#endif
I'm creating a plugin for October CMS that has a frontend form (component) with
{{ form_open({ request: 'onSubmitForm' }) }}
In the plugin there is a function onSubmitForm() with a validator.
If the validator fails I want to redirect to the page the form input came from ($this->page->url) but send the validator messages ($validator->messages()) and the original input of the form (post()) with it.
I've tried:
if ($validator->fails()) {
return Redirect::to($this->page->url)->withErrors($validator->messages())->withInput(post());
}
and if I put {{ errors }} on the page i do get a message
Object of class Illuminate\Support\ViewErrorBag could not be converted
to string
which I then fixed by using:
{% for error in errors.all() %}
<li>{{ error }}</li>
{% endfor %}
and {{ errors.first('name') }}
but the {{ input }} doesn't even return an error.
Am I doing the redirecting wrong? Or does it have to do with how Twig and Blade are so completely different? Is there a way to prefill old input values and error messages?
You can output the old input value with this twig
{{form_value('my_input_name')}}
october cms form doc
As you can read in the very top you can "translate" php exemple to twig by changing "method name" to lower case and "::" to _
exemple:
// PHP
<?= Form::open(..) ?>
// Twig
{{ form_open(...) }}
hope it will help.
this is my regular code for blade
#if (count($errors) > 0)
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>{{trans('messages.sorry')}}</strong>
<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
Instead of redirecting to the same page where the form was submitted from, just use Ajax! You can do in couple ways.
instead of form_open, use form_ajax.
Here is an example:
form_ajax('onSubmitForm', { model: user, class: 'whateverclass', id: 'idoftheform', success:'doSomethingInJS(textStatus, data)'})
in PHP, you can return your error message as
return ["ErrorMsg" => 'this is some error']
Then in JS you can display it:
function whateverClass (textStatus, data){
alert (data.ErrorMsg);
$('#alertHolderDiv').html(data.ErrorMsg);
}
another way would be to use a partial! And once you throw an error you can use "update" in ajax command to update the partial. The partial will be overwritten with the new message.
I have a twig template (home.twig), and I'm using
{{ render(controller('WebsiteUserBundle:Registration:register',{ 'template': 'popup'} )) }}
inside that template to render another template (login.twig), which is used to login the user from a popup.
The problem is that the form_widget isn't rendered, but the form_label is.
This is part of my login template:
<div class="row-fluid">
{{ form_label(form.email, 'Email:')}}
{{ form_widget(form.email, { 'attr': {'class': 'span12'} }) }}
</div>
And by "it's not rendered", I mean that there isn't even an empty div or input next to the label element in the DOM.
Why is this happening?
I had the same issue and was because I had the follow sentence before the form_widget
{{ form_rest(form) }}
Check that the form_rest be after of all your form_widget.
if you get only form_widget without extra params, like this :
{{ form_widget(form.email) }}
do you have more informations or any output ?