Search Application
Search Form & Drug Discount Network API
To allow website visitors to search the Discount drug Network API database, we first have to create an appropriate search form in HTML like so:
<!-- === DDNetwork - Search Form === -->
<div id="pharmacy__search" class="container mb-4">
<div class="row">
<form id="pharma__search2" action="<?php echo htmlentities(get_permalink());?>home#pharmacy__search"
method="post"
class=" mx-auto"
style="background-color: <?php echo $custom_search_form_main_bg_color;?>;
border-radius:10px;
border: 4px solid <?php echo $custom_search_form_border_color;?>;">
<br>
<div class="form-row
px-2 px-sm-2 px-md-3 px-lg-4
mb-2 mb-sm-2 mb-md-3 mb-lg-4"
>
<div class="col-md-6">
<label class="w-100">
<div class="input-group">
<div class="input-group-prepend">
<span class="form__span pt-2 pr-2">Drug Name</span>
</div>
<input type="text" name="drug_name" class="form-control" required>
</div>
</label>
</div>
<div class="col-md-6">
<label class="w-100">
<div class="input-group">
<div class="input-group-prepend">
<span class="form__span pt-2 pr-2">Zip Code </span>
</div>
<input type="text" name="zip_code" class="form-control d-inline" required>
</div>
</label>
</div>
</div><!-- main -->
<div class="form__bottom pt-3">
<div class="row
px-2 px-sm-2 px-md-3 px-lg-4
mb-1 mb-sm-1 mb-md-2 mb-lg-2"
>
<div class="col-md-7 mobile-font">
<div class="row">
<div class="col-sm-6">
<div>
<label>
<div class="input-group">
<div class="input-group-prepend">
<span class="form__span_b pt-2 pr-2" >Dosage</span>
</div>
<input type="text"
name="strength"
class="form-control d-inline"
required>
</div>
</label>
</div>
</div>
<div class="col-sm-6 pb-2 pb-sm-2 pb-md-3 pb-lg-3">
<div class="row">
<div class="col-6">
<div>
<label class="sr-only">Strength Unit of Measure</label>
<select name="strength_unit_of_measure">
<option value="MG">MG</option>
<option value="%">%</option>
<option value="-1200 UNIT">-1200 UNIT</option>
<option value="-1500 UNIT">-1500 UNIT</option>
<option value="-1600 UNIT">-1600 UNIT</option>
...
</select>
</div>
</div>
<div class="col-6">
<div>
<label class="sr-only">Formulation</label>
<select name="formulation">
<option value="TABS">TABS</option>
<option value="AERO">AERO</option>
<option value="AERP">AERP</option>
<option value="AERS">AERS</option>
<option value="AEPB">AEPB</option>
...
</select>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-5 mobile-font">
<div class="row">
<div class="col-7">
<div>
<label>
<div class="input-group">
<div class="input-group-prepend">
<span class="form__span_b pt-2 pr-2">Quantity</span>
</div>
<input type="text" name="quantity" placeholder="30" value="30" class="form-control d-inline">
</div>
</label>
</div>
</div>
<div class="col-5">
<div>
<label class="sr-only">Search Type</label>
<select name="search_type">
<option value="Generic">Generic</option>
<option value="Brand">Brand</option>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="row
px-2 px-sm-2 px-md-3 px-lg-4
pb-2 pb-sm-2 pb-md-3 pb-lg-3
">
<div class="col-md-8">
<div class="mx-4
py-2 "
style="background:#fff;color:#000;border-radius:5px;">
<h4 class="text-center px-2 px-sm-3 px-md-4 px-lg-5">
Search Pharmacies & Compare Prices In Your Location
</h4>
</div>
</div>
<div class="col-md-4
px-4 px-sm-5 px-md-3 px-lg-3"
>
<input type="submit"
value="search"
name="search"
class="h-75 w-100 mt-3 get__card"
style="background:<?php echo $custom_search_form_button_bg_color;?>;
color:<?php echo $custom_search_form_button_text_color;?>;
border: 2px solid <?php echo $custom_search_form_button_border_color;?>;
font-weight:700;
font-size:25px;
text-transform:uppercase;"
>
</div>
</div>
<div class="d-none">
<label class="sr-only">Package Size</label>
<input type="text" name="package_size" placeholder="0" value="0" class="d-none" required>
</div>
<div class="d-none">
<input type="text" name="limit" placeholder="10" value="12">
</div>
</div>
</form>
</div>
</div>
Next we must establish Connection with the DDN API like in the following PHP code
<?php
$wsdl = "https://api.***************.php?wsdl";
$login = array('login' => '**********',
'password' => '***********'
);
$soapClient = new SoapClient($wsdl, $login);
?>
Drug Discount Network | Soap Request
After the visitor fills out the form and submits the data (pharmacy, drug, etc.), this information will be stored in the PHP predefined $_POST variable. We now want to get the search results from the discount drug Network via API. Therefore we have to make a SOAP Request including the data from our $_POST variable.
if(isset($_POST["search"]) ):
$drug_name = strtoupper($_POST["drug_name"]);
$zip_code = $_POST["zip_code"];
$formulation = $_POST["formulation"];
$strength = $_POST["strength"];
$strength_unit_of_measure = $_POST["strength_unit_of_measure"];
$package_size = $_POST["package_size"];
$quantity = $_POST["quantity"];
$search_type = $_POST["search_type"];
$limit = $_POST["limit"];
// Make the Soap Request
$soapClient = new SoapClient($wsdl, $login);
$request =
"<Envelope xmlns='https://schemas.xmlsoap.org/soap/envelope/'>
<Body>
<pharmacies_search xmlns='urn:pharmacies_search'>
<Drug>
<drug_name >" . htmlentities($drug_name) . "</drug_name>
<zip_code>" . htmlentities($zip_code) . "</zip_code>
<formulation>" . htmlentities($formulation) . "</formulation>
<strength>" . htmlentities($strength) . "</strength>
<strength_unit_of_measure>" . htmlentities($strength_unit_of_measure) . "</strength_unit_of_measure>
<package_size>" . htmlentities($package_size) . "</package_size>
<quantity>" . htmlentities($quantity) . "</quantity>
<search_type>" . htmlentities($search_type) . "</search_type>
<limit>" . htmlentities($limit) . "</limit>
</Drug>
</pharmacies_search>
</Body>
</Envelope>";
$err_response = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="https://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="https://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="https://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:pharmacies_search"><SOAP-ENV:Body><ns1:pharmacies_searchResponse xmlns:ns1="urn:pharmacies_search"><return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:Pharmacy[0]"></return></ns1:pharmacies_searchResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>';
$location = $wsdl;
$action = "pharmacies_search";
$version = 1;
$response = $soapClient->__doRequest($request, $location, $action, $version);
...