Child pages
  • Chapter 6 - Creation - Remote Online Form

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

As we saw in Section 3.3 (List customers) it is possible make an array of parameters for "get ", "resource," and "id." It is also possible to specify only one URL this way:

Code Block

$xml = $webService->get(array('url' => 'http://myprestashop.com/api/customers?schema=blank'));

Here, we get the entire XML variable from an empty client.

Code Block

<prestashop>
  <customer>
    <id_default_group/>
etc...Beginning of the XML file retrieved:

...

Getting of all fields

Code Block

$resources = $xml->children()->children();

Path of all fields and part of the dynamic creation of form fields in a table

Code Block

foreach ($resources as $key => $resource) {
	echo '<tr><th>' . $key . '</th><td>'; 
	echo '<input type="text" name="' . $key . '" value=""/>';
	echo '</td></tr>';
}

Once the data is passed in POST, we combined the data sent with the blank XML file, which is the same technique used for updating data.

Code Block

foreach ($resources as $nodeKey => $node) {
	$resources->$nodeKey = $_POST[$nodeKey];
}

Calling the web service is similar to what we have seen previously:

Code Block

$opt = array('resource' => 'customers');
$opt['xmlpostXml'] = $xml->asXML();
$xml = $webService->add($opt);

...