Child pages
  • Chapter 6 - Creation - Remote Online Form

Versions Compared

Key

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

Wiki Markup\\ *Objective{*}: A Web application to list and create a new customer. *
Difficulty{*}: ** \\ <span style="color: #79b51c"><strong>Preparation:</strong></span> <span style="color: #0070c0">Copy</span> the file <span style="color: #0070c0">list
Preparation:
Copy the file list_the_clients.php</span> php from Section 3.3 to a file named <span style="color: #0070c0">Cnamed C-CRUD.php</span> php at the root of your Web server. \\
The addition of resource can be likened to an upgrade from an empty element. \\
But how do we retrieve an XML formatted as an empty client? \\
In the web service, there is a method to retrieve an empty XML. It is accessible via a URL formatted as follows: \\ \\ \\ <span style="color: #0070c0">Note :</span> It is possible to replace the parameter scheme value "blank" with "synopsis" in order to gain more information about the resource fields.

Note :
It is possible to replace the parameter scheme value "blank" with "synopsis" in order to gain more information about the resource fields.http://mystore.com/api/\[enEN:resource name\]?schema=blank \\ \\ \\ \\ As we saw in Section

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: \\
$xml = $webService->get(array('url' => 'http://mystore.com/api/customers?schema=blank')); \\ \\ \\


Here, we get the entire XML variable from an empty client. \\ <prestashop> <customer>
<prestashop>
<customer>
<id_default_group/>
etc...Beginning of the XML file retrieved: \\ \\ \\ \\ \\ retrieved:

Wiki Markup
We can then, thanks to the many fields we have, create an associated form.
\\
Getting of all fields:
\\
$resources = $xml->children()->children();
\\
\\
Path of all fields and part of the dynamic creation of form fields in a table:
 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.
 foreach ($resources as $nodeKey => $node)  \{   $resources->$nodeKey = $_POST\[enEN:$nodeKey\];  \}
\\
\\
\\
\\
\\
Calling the web service is similar to what we have seen previously:
 $opt = array('resource' => 'customers');  $opt\[enEN:'postXml'\] = $xml->asXML();  $xml = $webService->add($opt);
\\
\\
\\
\\
Now create a script that adds a client. Remember that some fields are mandatory, so do not forget to fill them out.
\\
If you have trouble, look at the code for "3-Create.php.
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\