simsalabim/sisyphus

Export data to the server?

Closed this issue · 11 comments

Would it be possible to store partially filled forms to the server? Maybe using an AJAX call?

+1 for that, or persist data after submit, could be useful for example in search forms which you don't want to save to database but want to keep state when coming back...

@BarisW, sisyphus is a front-end solution, but what you propose deals with server-side. Thus you can send those ajax calls on your own in a separate script and it wouldn't break any of the concepts.

@simsalabim I'm aware that sisyphus is a front-end solution, but is there an after() function or a hook where my JS can plugin to? Can my code re-use parts of sisyphus or do I have to write all myself?

@BarisW after what hook do you mean?

I assume that the onSave() function can be used, but any thoughts how this works? Can we send the form data to the callback function.

Like:

onSave: function() {
writeAjaxCall(field, value);
},

Is there a field, value etc?

You can use plain selectors and select the fields you want inside of this callback.

onSave: function() {
  sendAjaxRequest( $('#myfield'), $('#myvalue') )
}

hi @simsalabim, that's useful, but I'd like to make it generic. It would be awesome if the module could send the changed form element with the request. Like

onSave: function(element, value) {
  sendAjaxRequest( element, value )
}

@BarisW could you please clarify your solution design. What if several fields were changed? I don't think that this is a good idea to trigger onSave multiple times each time passing new changed pair of element and its value.

Passing all the changed elements as a collection looks better, but this is quite complicated, because it requires fields states management on the plugin level (was it changed or not, and it should be handled in real time as user can add some characters and then delete them, so state changes dynamically). Too much of work.

onSave: function ( changedElements ) {
  for ( element in changedElements ) {
    // of course I'm not gonna send ajax requests while iterating
    // this is just to show discussed functionality
    sendAjaxRequest( element.previousValue, element.newValue ) 
  }  
}

Anyway if you provide a pull request demonstrating this functionality I'd gladly review it.

The use case is that a client wants to see the data of partly-filled in forms. Think of donation forms. A user fills in his mail, name, etc but decides not to submit the form for specific reasons. My client wants to be able to contact this client nonetheless, even if the form has not been submitted.

So I'm looking for a way to write the unsubmitted data to the database.

The reason I want this generic is that I'd like to be able to re-use this piece of code on several user-generated forms, on fields I don't know the name of.

Ideally I'd be able to send an AJAX call with the key/value after a field is saved to the localstorage.

@BarisW a message above I described possible ways of implementation and commented them a bit, I got what you want, and this is not what the plugin is intended for. Sisyphus is about to save users data and prevent them being lost on a number of occasions.

Despite the fact I cannot modify the plugin to suit everyone's use cases though, I think that the concept of writing the unsubmitted data to the database is quite spammy/malicious and annoys users. I wouldn't want anyone to contact me without my permission. And I don't want forms to send the data to servers if I don't press submit button.

I couldn't agree more ;)

Let's see if I can convince my client.