There are, say, 10 fields on page1 and hyperlink to page2. Also there is hyperlink on page2 to page1. I fill 5 fields and click on the hyperlink. Then I click on the hyperlink on page2 and return to page1. Is it possible to save filled fields and how?
Additional question: what if page2 modifies fields of page1. For example, creates new choice in multichoice field.
Django has implemented solution which allow to split forms on multiple web pages. It is called form wizard. Check here for the tutorial.
EDIT 1#
Check this questions up: Django Passing data between views, How do you pass or share variables between django views?
You can save filled fields using cookies via javascript after clicking on the link and before going to another page. For example it's possible to use this jQuery plugin jQuery-cookie. As documentations says:
A simple, lightweight jQuery plugin for reading, writing and deleting cookies.
Create session cookie:
$.cookie('the_cookie', 'the_value');
Create expiring cookie, 7 days from then:
$.cookie('the_cookie', 'the_value', { expires: 7 });
Create expiring cookie, valid across entire page:
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
Read cookie:
$.cookie('the_cookie'); // => 'the_value'
$.cookie('not_existing'); // => null
Delete cookie by passing null as value:
$.cookie('the_cookie', null);
Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie.
Related
I'm looking on how to update the ajax configuration dynamically using data from a resource when updating a record. Django REST expects the id at the end of the url and the request method must be type PUT
I've spent some time figuring out how to update the ajax request made by the Datatable Editor plugin. I'm using Django Rest as the backend. This might be useful for some people looking for a similar answer.
Technically you can update the ajax options if the editor object before it sends the request by using the preSubmit Event.
editor.on('preSubmit', (e, request,) =>{
let _url = new URL(window.location.origin + "/" + editor.ajax().url)
if(request.action == 'edit'){
editor.ajax().url = `${_url.protocol}//${_url.host}/api/v1/some-endpoint/${Object.keys(request.data)[0]}/${_url.search}`;
editor.ajax().type = 'PUT'
}
editor.ajax().data = request.data[Object.keys(request.data)]
})
This will update the ajax configuration of the edit request right before it get sent. Django Rest expects a PUT request and the id of the record to be added at the end of the URL. As you can see we grab the id from the data object (Its the first key of the request.data object), and we can also change the type of request to PUT.
typo3 9.5.8
we are implementing a newsletter subscription flow with multiple steps, on submit of the second step we query graphQL in a finisher to see if the Email is valid to subscribe or not - and we set a cookie with the "state" of the email address.
setcookie("isEmailSubscribable", ($content->data->isEmailSubscribable) ? "1" : "0", time() - 3600, "/", "x.at", false);
we have to display a message on the third step based on that "state" written into a cookie. but no matter what i try the cookie does not get set (i guess).
whats the deal with cookies and typo3? is it to late to set a cookie inside a form finisher? but if yes how could i solve this?
help is much appreciated
Inside the Finisher:
// Set a cookie
$this->getTypoScriptFrontendController()->fe_user->setKey('ses', 'value', 'test');
// Get the cookie
$this->getTypoScriptFrontendController()->fe_user->getKey('ses', 'test');
ses are Session cookies
user This cookies require a fe_user to be logged in
Value can be an array, it will be stored serialized in the Database fe_sessions.ses_data
UPDATE:
Or you can try it with an PSR-15 Middleware: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/RequestHandling/Index.html
In your Middleware Class you get a $request and $response and use them to set or read a cookie:
// Write a cookie
$response = $response->withAddedHeader(
'Set-Cookie',
$cookieName . '=' . $yourValue . '; Path=/; Max-Age=' . (time()+60*60*24*30)
);
// Read a cookie
$request->getCookieParams()[$cookieName];
You just have to check request for email address and maybe an hidden field to detect that your for was submitted.
I have a users model which fetches data from github users api (https://api.github.com/users). While displaying the list there is a add button which should add the user to a shortlist section below and which has a remove button to remove user from shortlist. I don't have api to save shortlist data. What is the best approach to make this work?
Try 1: Created a shortlist model and used store.push
this.store.push({
data: [{
id: user.id,
type: 'shortlist',
attributes: {
login: userData.login,
avatar_url: userData.avatar_url,
type: userData.type
}
}]
});
and used item.unloadRecord(); to remove from model. But did nor found a way to fetch all record and show as this.store.peakAll('shortlist') wasen't working.
Try 2: Used localstorage to add user to shortlist, display and remove but here it needs page reload to display the add/remove changes as i used setupController to get the items from localstorage.
Please suggest how to do this in best possible way.
I know how to make a post to a Facebook page via the API using PHP SDK, that is done like this:
$facebook->api('/xxxxxxxxxxx/feed', 'post', array('message'=> 'Hello world!', 'cb' => ''));
Where xxxxxxxxxxx is page id ;)
But doing that, I post to that page as me, Jamie, and not as the Page itself (admin).
So how do I post as Admin/Page instead of myself?
Thanks you for your time!
ANSWER (for lazy people):
First of all you need to make sure you have access to manage pages for user, ex:
<fb:login-button autologoutlink="true" perms="manage_pages"></fb:login-button>
Now you also gets a special token for every page user have access to once you get them.
PHP SDK Example:
//Get pages user id admin for
$fb_accounts = $facebook->api('/me/accounts');
//$fb_accounts is now an array
//holding all data on the pages user is admin for,
//we are interested in access_token
//We save the token for one of the pages into a variable
$access_token = $fb_accounts['data'][0]['access_token'];
//We can now update a Page as Admin
$facebook->api('/PAGE_ID/feed', 'post', array('message'=> 'Hello!', 'access_token' => $access_token, 'cb' => ''));
Check out this note regarding your question: http://developers.facebook.com/docs/api > Authorization > Page impersonation.
Long story short, you need the manage_pages extended permission.
And btw, have you checked this first ?
How can we delete a cookie [jquery plugin cookie $.cookie()] or set it to null on one page from a diff page? I want to delete a cookie on page 2 from page 1 on button click. I tried so many diff ways and I was unsuccessful. please help. is there any work around?
A cookie is not tied to a page. It is stored on the client computer/browser and sent along each request to the server. So if you set it to null on one page it will be deleted and no longer sent.
Rather old question, but I found it so....
Make sure to include the path on the Delete to match the one on the Set
$.cookie('key', 'value', { path: '/' });
....
$.cookie('key', null, { path: '/' });