php - Display a Custom Post-Submit Message after NinjaForm Submission?

one text

I'm using NinjaForms to submit tickets to our ticketing system.

By means of a WP Hook, I'm able to shoot off the ticket creation script; however, what I'd really like to do is capture and display the server response to the user that verifies that their ticket was created and what their ticket # is.

I'm happy to find a way to achieve this by either a) passing data back into Ninja Forms through their submission message or b) to forgo their submission message altogether and simply obliterate the content on the current page to show the server result.

I'm no great Wordpress wizard when it comes to custom actions and scripts.

The hook I have does what I need to do and can glean the server response, but I've also read Actions should not have return data. But is there a way that I can use this action to inject the information I require into the page (while also obliterating elements I do not want)? Or to pass the info to a JavaScript function on the frontend that could perform the same task? I'm not sure what would be the "Wordpress way" of handling such a thing.

I basically want to create my own success message but based on the server response from the ticketing system, which would have been returned in my action hook.

In functions.php:

//Action added. This is called with a NinjaForm "WP Hook"
add_action( 'wp_ninjaform_data_tracker', 'wp_ninjaform_data_tracker_callback' );

function wp_ninjaform_data_tracker_callback( $form_data ){ 

    //Ninjaform Fields, gathered and made into an associative array
    $form_fields   =  $form_data[ 'fields' ];
    $field = array();
    foreach ($form_fields as $key => $one) {
        $field[$one['key']] = $one['value'];
    }

    //Example of one field
    $fullname = $field[ 'fullname' ];

    //Can't include reala URL for the ticket system, but this is the URL I send the final data to to create a ticket
    $url = "https://www.faketrackerurl.com/REST/1.0/ticket/new/";
    $data = "user=username&pass=password&content=Requestor: \"".$fullname."\n";
    
    //Sends the request. Returns server response.
    function do_post_request($url, $data, $optional_headers = null) {
        $params = array('http' => array(
        'method' => 'POST',
        'content' => $data));
        if ($optional_headers!== null) {
            $params['http']['header'] = $optional_headers;
        }
        $ctx = stream_context_create($params);
        $fp = @fopen($url, 'rb', false, $ctx);
        if (!$fp) {
            throw new Exception("Problem with $url, $php_errormsg");
        }
        $response = @stream_get_contents($fp);
        if ($response === false) {
            throw new Exception("Problem reading data from $url, $php_errormsg");
        }
        return $response;
    } 
    $response = do_post_request($url,$data);
}

I would like to use the $response data in either my success message within NinjaForms or to create my own custom success message after NinjaForms is finished with its submission.

When you don't choose to have a Success Message, the page goes blank. I tried to use this functions.php to echo a JavaScript call to call "alert" just to see it was working, and it didn't work. I am a frontend developer, so my instinct is to simply call a frontend solution, but I don't know if that's possible.

I have also looked into the NinjaForms code, hoping to find a way to pass information back to the Success Message or to try to discover ways to find hooks to perform actions based on their events, but it is not my wheelhouse, and I'm not terribly fond of their documentation. I'm still at it, but any help would be appreciated.

Much thanks.

Source