i am fighting from some days about avoing resubmit data in a cake view when i refresh the page.
I will explain the data process
One view with an to /quotes/select/
saving data in function select
When i arrive to the page select.ctp i have the problem on the refresh. Everytime i refresh a new quote is saved into the DB.
In this case no forms. Is there a solution?
Working on this matter i found the Security Component and i would like to use for the "Forms". I tried to use but i get the following error:
Missing Helper
Error: SecurityHelper could not be found.
Error: Create the class SecurityHelper below in file: app/View/Helper/SecurityHelper.php
Where can i find it? Thank in advance.
Considering that you have something similar to this:
if ($this->Quotes->save($quote)) {
$this->Flash->success(__('Your quote has been saved.'));
}
You can add a redirect to the same page which will clear the POST request that is left in the browser
if ($this->Quotes->save($quote)) {
$this->Flash->success(__('Your quote has been saved.'));
return $this->redirect([]); // <----- Redirects to same page
}
Related
I've been quite pleased with how remote pagination on Tabulator works with automatic ajax loading, but I can't seem to find a way to set the page that is displayed when the table is first loaded. table.setPage(pageNum) only works for me after the first page has been fetched and rendered; if I do something like
new Tabulator("#my-tabular-table", { lots of stuff }).setPage(5)
then I get a Pagination Error - Requested page is out of range of 1 - 1: because the page count hasn't been received from the server yet.
Is there some way of doing this? Am I missing something? I realize that I could hook into some callback and switch to the desired page immediately after the first page has been loaded, but I'd rather not wait for an extra server call.
You can use the paginationInitialPage option in the table definition to set the page number for the initial load:
var table = new Tabulator("#example-table", {
pagination:"remote", //enable remote pagination.
paginationInitialPage:2, // this option can take any positive integer value
});
my simple view file
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<?php ActiveForm::begin()?>
<?=Html::submitButton('something')?>
<?php ActiveForm::end()?
Clicked the button. After I reload the page and browser shows me
this
So how can I remove this?
This problem happen when you submit data in a form and then refresh the page
Browsers should stop this, or at least prompt if you want to resend the data,
but the best way to prevent this from happening is submit the data .. and manage the submit properly.
In you case your submit repeat the index action because you don't manage proper the action code
(all you're being made does not produce the creation of a new model to be complete so as not prroduce displaying a result.
or any other action ..
your code continues to call the same action that produces post calling for action and so on)
try adding a simple die() or a render for another view
public function actionIndex()
{
if (Yii::$app->request->post('submit')==='my_value') {
echo "Button my_value Clicked";
die(); // or render a proper view
}
return $this->render('index');
}
This is basic browser behavior. Your form is doing a POST request and obviously when you try to refresh it will ask for this. Even if you write a basic html page without yii, you will still have this.
When user tries to navigate away to another portal page before current page has finished loading, error message saying - There was unexpected error. Please refresh the current page comes up for the portlets which were loading before the redirection happened.
On debugging, it was found that it comes up from portlet.js and its failed() handler from Ajax call.
Can we restrict it for a specific portlet?
Thanks
As per my observation, failure method has three arguments - event, id, obj.
In some other parts of this JS file (portlet.js), event.portletId is used to fetch portlet ID. Its worth to give a try if you can fetch your portlet ID inside failure method.
Then you can apply condition on portlet ID of your choice to display the message or not.
if (event.portletId == '<your-portlet-instance-id>') {
placeHolder.placeAfter('<div class="portlet-msg-error">' +
Liferay.Language.get('there-was-an-unexpected-error.-please-refresh-the-current-page')
+ '</div>');
}
I have issue from client end with jsf 1.2 as explained below
I am navigating on click on command button to the url below
test/editProject.jsf?value=123
If any field are missing I am using addErrorMessage('id','string') and returning fail in validation method. The error message is displayed under that component.. I am fine till this..
The problem is the url is displayed as
test/editProject.jsf
Here the value queryString is missing..if the user correct the error and click on save it works fine..it is working as per jsf cycle
Issue
My client is pressing enter on the browser url tab which has the url test/editProject.jsf. I told him to use F5 button to refresh but he didn't agreed.. any idea how to retrieve the query string back on getting error message.
I have used redirect in my project but I think here its not good idea to use..
Please let me known if you any solution for this..
Thanks for help.
I'm trying to create a collection_action in ActiveAdmin which allows me to Import a CSV file and generate Subscribers from it. I want to be able to click an action_item link and be taken to a form in which I input the CSV file, and then do some work with it.
This is what I have so far:
ActiveAdmin.register Subscriber do
collection_action :import_csv, :method => :post do
render "import_csv"
end
action_item do
link_to "Import from CSV", import_csv_admin_subscribers_path
end
The view is also created, just blank at the moment. I've restarted the rails server, and rake routes outputs:
import_csv_admin_subscribers POST /admin/subscribers/import_csv(.:format) admin/subscribers#import_csv
batch_action_admin_subscribers POST /admin/subscribers/batch_action(.:format) admin/subscribers#batch_action
admin_subscribers GET /admin/subscribers(.:format) admin/subscribers#index
POST /admin/subscribers(.:format) admin/subscribers#create
new_admin_subscriber GET /admin/subscribers/new(.:format) admin/subscribers#new
edit_admin_subscriber GET /admin/subscribers/:id/edit(.:format) admin/subscribers#edit
admin_subscriber GET /admin/subscribers/:id(.:format) admin/subscribers#show
PUT /admin/subscribers/:id(.:format) admin/subscribers#update
DELETE /admin/subscribers/:id(.:format) admin/subscribers#destroy
However when I click the action item I get the error Couldn't find Subscriber with id=import_csv
If I change the method to :get it renders the view fine. I'm assuming the problem is my use of :post? Is it not possible to render a view if you're calling a controller action with that method?
edit Ok, yeah, it doesn't make sense to render a view with a post but then why does the ActiveAdmin doc suggest that you do the action this way for CSV imports? How are you supposed to # Do some CSV importing work here... without generation a form?
You need to add the method: :post option to the link to invocation, since there's no get action for that url.