Editor data submission

Editor data submission

wbyerswbyers Posts: 48Questions: 12Answers: 1

can I submit another string variable instead of action to the server using the editor?

Answers

  • allanallan Posts: 62,377Questions: 1Answers: 10,234 Site admin
    Answer ✓

    Yes, you can use preSubmit to modify the data that is being sent to the server.

    Allan

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    Okay, Sorry to bother you on this again, But i've tried to send other strings to my server component using action specifically editStock and editHeld. They don't work. The default action is still sent. Is there anything I have to do with the presubmit event to make it change the action/task. Or is that Locked in?

  • allanallan Posts: 62,377Questions: 1Answers: 10,234 Site admin

    Can you show me the code you were trying to use please?

    Allan

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    sure:
    editor.on('preSubmit', function( e, data, action ){
    console.log(data.data);
    console.log(action);

          $.each( data.data, function ( key, value ) {
             if(data.data[key]['held']!== undefined){
                console.log("held exists")
                action='editHeld';
             }
             if(data.data[key]['stock']!== undefined){
                 action='editStock';
             }
                console.log(action)          
           });          
        });     
    
  • allanallan Posts: 62,377Questions: 1Answers: 10,234 Site admin
    Answer ✓

    I see - thanks. You could use initSubmit to change the action, but since Editor needs to understand the variable internally, you can't change it to any old random string (it wouldn't know what yo do with editStock for example.

    Instead, what you would need to do in this case is add another parameter which would contain your custom value.

    Allan

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    wait so I can just add a third element to the function for initSubmit?

  • allanallan Posts: 62,377Questions: 1Answers: 10,234 Site admin
    Answer ✓

    No, but you can do:

    editor.on( 'preSubmit', function ( e, data, action ) {
      data.customAction = 'editHeld';
    } );
    

    Allan

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    Okay, thanks that helps a lot.

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    so on the server end that would be $_POST['data']['customAction'] right?

  • allanallan Posts: 62,377Questions: 1Answers: 10,234 Site admin
    Answer ✓

    Just $_POST['customAction'] would get it.

    Allan

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    Thanks.

This discussion has been closed.