Closed pyprism closed 10 years ago
Are you using the JSON or Rest save plugin?
JSON
I had to make a few tweeks to the save plugin to allow more data customisation, but I have made a working example here: https://github.com/PANmedia/raptor-example/blob/master/examples/csrf/example.php https://github.com/PANmedia/raptor-example/blob/master/classes/Raptor/CSRF/Example.php
https://github.com/PANmedia/raptor-editor/commit/aa660c46004cdd494dcccac42833e915c6f4b954
Thanks . But one thing I cant understand ... I am following https://www.raptor-editor.com/documentation/tutorials/basic-saving . Here is my code
$(function() {
$('.raptor-editable').raptor({
plugins: {
// Define which save plugin to use. May be saveJson or saveRest
save: {
plugin: 'saveJson'
},
// Provide options for the saveJson plugin
saveJson: {
// The URL to which Raptor data will be POSTed
url: 'http://localhost:8000/users/editor',
// The parameter name for the posted data
postName: 'raptor-content',
// A string or function that returns the identifier for the Raptor instance being saved
id: function () {
return this.raptor.getElement().data('id');
}
}
}
});
});
In this code where should I add csrf variable ?
As per https://github.com/PANmedia/raptor-example/blob/master/examples/csrf/example.php
var csrf = /* generate CSRF token here */;
$(function() {
$('.raptor-editable').raptor({
plugins: {
// Define which save plugin to use. May be saveJson or saveRest
save: {
plugin: 'saveJson'
},
// Provide options for the saveJson plugin
saveJson: {
// The URL to which Raptor data will be POSTed
url: 'http://localhost:8000/users/editor',
// The parameter name for the posted data
postName: 'raptor-content',
// A string or function that returns the identifier for the Raptor instance being saved
id: function () {
return this.raptor.getElement().data('id');
},
post: function(data) {
data.csrf = csrf;
return data;
}
}
},
bind: {
saved: function(data, status, xhr) {
csrf = data.csrf;
},
saveFailed: function(data, status, xhr) {
csrf = data.csrf;
}
}
});
});
Note: you need to regenerate a new CSRF token every time you save.
Thank you so much :smile:
How to send CSRF token from raptor editor?