Extract Form Fields Data From Word Document in PHP With Aspose.Words REST API

I am using the PHP example from this page:

I am using the document provided mentioned in the page to test the API: https://docs.aspose.cloud/words/formfields/FormFilled.docx

The api just just returns an empty object ‘{}’

Is the example out of date?

@FFSPUD

I have installed Aspose.Words Cloud SDK for PHP 22.3 from Packagist via composer and tested the following code to extract from fields date from Word document. It returns form fields data in response successfully.

Please double check you are using the latest SDK version. However, if the issue persists then please share your script file with us without your credentials. We will look into it and will guide you.

Read MS Word Document Form Fields in PHP

<?php

require_once('D:\xampp\htdocs\aspose-words-cloud-php-master\vendor\autoload.php');


try {

	//TODO: Get your ClientID and ClientSecret at https://dashboard.aspose.cloud (free registration is required).		
	$ClientSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxx";
	$ClientId="xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx";


	$wordsApi = new Aspose\Words\WordsApi($ClientId,$ClientSecret);	
	
        $fieldFolder = "data";

        $requestDocument = $fieldFolder . "/FormFilled.docx";
        $request = new Aspose\Words\Model\Requests\GetFieldsOnlineRequest(
            $requestDocument,
            "sections/0",
            NULL,
            NULL,
            NULL
        );

        $result = $wordsApi->getFieldsOnline($request);
	print_r($result);
        
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}

?>

Response:

Aspose\Words\Model\FieldsResponse Object ( [container:protected] => Array ( [request_id] => Root=1-62470958-49ebc1d22f2ca1b91efee104 [fields] => Aspose\Words\Model\FieldCollection Object ( [container:protected] => Array ( [link] => [list] => Array ( [0] => Aspose\Words\Model\Field Object ( [container:protected] => Array ( [link] => [node_id] => 0.0.1.0.1.0.1 [field_code] => {FORMTEXT } [locale_id] => 1033 [result] => John Doe ) ) [1] => Aspose\Words\Model\Field Object ( [container:protected] => Array ( [link] => [node_id] => 0.0.1.1.1.0.1 [field_code] => {FORMTEXT } [locale_id] => 1033 [result] => 1982-08-20 ) ) [2] => Aspose\Words\Model\Field Object ( [container:protected] => Array ( [link] => [node_id] => 0.0.1.2.1.0.2 [field_code] => {FORMTEXT } [locale_id] => 1033 [result] => 2,130.50 ) ) [3] => Aspose\Words\Model\Field Object ( [container:protected] => Array ( [link] => [node_id] => 0.0.1.3.1.0.1 [field_code] => {FORMCHECKBOX } [locale_id] => 1033 [result] => ) ) [4] => Aspose\Words\Model\Field Object ( [container:protected] => Array ( [link] => [node_id] => 0.0.1.4.1.0.1 [field_code] => {FORMDROPDOWN } [locale_id] => 1033 [result] => ) ) ) ) ) ) )

Thank you for responding, I have worked out what I was doing wrong:
Instead of:

print_r($result)

I was using:

echo json_encode($result, JSON_PRETTY_PRINT);
1 Like