Add an CURLOPT function

Add an CURLOPT function

bitmacherbitmacher Posts: 15Questions: 6Answers: 0

Hello together,

First of all I want to say that these DataTables and the editor are totally brilliant tools, which relieved me a lot of programming work!

Now I have a very stable version with an adress database with overall 50k adress data. It works completely fine with column searching, fixing headers, formButtons, export and import functions and so on. Now I need a functionality with an additional external PHP CURLOPT function.

That means: Delete the selected contact in a row of the database and also delete the contact in an external system with only the delete button and one click.

Javascript adress.js

{
  extend: "remove",
  editor: editor,
  text: "Delete contact", 
  className: 'btn-edit',
  formButtons: [
    { text: 'Cancel', action: function () { this.close(); } },
    { text: 'Delete contact' ,               
   
    Insert code ........ something like this ???

    action: function (e, dt, node, config) {
        var emaildata = table.cell('.selected', 9).data();
        External URL ('delete_contact.php?email=' + emaildata ..........
        }
      }


   ],
},

PHP-file delete_contact.php

  if ($newsletter == "1") {

        // delete contact in the newsletter system
        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, "https://xxx.yyy.com/contact.php?email=$emaildata");          
        curl_exec($c);
       
        $response_info = curl_getinfo($c);
        curl_close($c);            
                
        echo "<p>Delete contact in both systems</p>";      
  
    } else {

        echo "<p>Delete contact in database</p>";
    }   

How can I integrate the CURLOPT function? Is it possible to integrate it in the staff.php like this?

PHP-file staff.php


Field::inst( 'email' ) ->validator( Validate::unique( ValidateOptions::inst() ->message( 'message' ) ) ) if ($newsletter == "1") { // delete contact in the newsletter system $c = curl_init(); curl_setopt($c, CURLOPT_URL, "https://xxx.yyy.com/contact.php?email=$emaildata"); curl_exec($c); $response_info = curl_getinfo($c); ..... .....

Thanks in advance for any idea or short help.

Best regards
Mac

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    Thanks for the kind words. It sounds like you want to use a server-side event for that, postRemove should do the trick.

    Colin

  • bitmacherbitmacher Posts: 15Questions: 6Answers: 0

    Hello Colin,

    thank you for your information and sorry for the late reply. That's absolutely the right trick. It's very easy to remove or edit another database with this function.

    PHP-File: staff.php

    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'database' )
        ->fields(
            Field::inst( 'email' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'Input required ' )  
                ) )
                ->validator( Validate::unique( ValidateOptions::inst()
                    ->message( 'text message' ) 
                ) )
                ->validator( Validate::email( ValidateOptions::inst()
                    ->message( 'text message correct mail' )    
                ) ),
            Field::inst( 'newsletter' )
                        ->setFormatter( function ( $val, $data, $opts ) {
                    return ! $val ? 0 : 1;
                } ),
              )
    
    ->on( 'postRemove', function ( $editor, $id, $values ) {
            if ( $values['newsletter'] == '0' OR $values['newsletter'] == '') {
                mail( 'post@mailxyz', 'Row deleted', 'Row with id '.$id.' deleted!' );
                // delete contact in the second system
                $c = curl_init();
                curl_setopt($c, CURLOPT_URL, "https://xxx.yyy.com/contact.php?email=$emaildata");         
                curl_exec($c);
    
                .....and so on.....
            }
    
    

    Thanks a lot.....

    Mac

This discussion has been closed.