Need to pass column value as variable to external PHP form.

Need to pass column value as variable to external PHP form.

boicenetboicenet Posts: 47Questions: 12Answers: 1

I'm looking at the example code in the "Cutomised control buttons" post. I want to set a variable equal to a column value in the selected table row and pass it as a parameter to a separate php form page. I am aware that I can create an action that opens the external page when the button is clicked.

Can I modify the following code in a way so that instead of updating the table row as for salary below I set a variable to the (editor.get('salary') value and pass it as a parameter to my separate form page (e.g., /formpage.php?salary=<variable>)?

Thanks.

buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            {
                extend: "selectedSingle",
                text: "Salary +250",
                action: function ( e, dt, node, config ) {
                    // Immediately add `250` to the value of the salary and submit
                    editor
                        .edit( table.row( { selected: true } ).index(), false )
                        .set( 'salary', (editor.get( 'salary' )*1) + 250 )
                        .submit();
                }
            },
            { extend: "remove", editor: editor }
        ]

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,819Questions: 1Answers: 10,517 Site admin
    Answer ✓

    You don't really need to bother with the Editor aspect at all for that. You could just use:

    {
      extend: "selectedSingle",
      text: "My button",
      action: function ( e, dt, node, config ) {
        var rowData = dt.row( { selected: true } ).data();
        window.open( ' /formpage.php?salary='+rowData.salary );
      }
    }
    

    Allan

  • boicenetboicenet Posts: 47Questions: 12Answers: 1

    Thank you, Allan! Works great!

This discussion has been closed.