2

I have a html form with 3 selector:

a. Room -> 1, 2, 3, 4, 5, 6
b. Adults -> 1, 2, 3, 4, 5, 6
c. Childs -> 0, 1, 2, 3, 4, 5

THe php arrays that i need to get looks like: Example 1 room with 2 adults

$rooms[] = array(array("paxType" => "Adult"), array("paxType" => "Adult")); 

Example 2 rooms ( one room is with two adults and the second room si with 2 adults an one child

$rooms[] = array(array("paxType" => "Adult"), array("paxType" => "Adult"));
$rooms[] = array(array("paxType" => "Adult"), array("paxType" => "Adult"), array("paxType" =>"Child", "age" => 8)); 

The variables that i receive from the form are as below:

$City= $_POST['City']; - text
$CheckIN= $_POST['CheckIN']; - text (date)
$CheckOUT= $_POST['CheckOUT']; - text (date)
$Rooms= $_POST['Rooms']; - selector (1,2,3,4,5,6)
$Adults= $_POST['Adults']; - selector (1,2,3,4,5,6)
$Childs= $_POST['Childs']; - selector (0,1,2,3,4,5) 

Form is workink fine for text and date input fields. How can i translate the html form request to get into the a bove look like php arrays. Thank you for your time.

Entire code is:

// create SOAP client object
  $client = new SoapClient("http://www.bookingassist.ro/test/book.wsdl", array('trace' => 1));

  try {
      function addPaxType($type = null, $amount = 0)
{
    $pax = array();
    for ($i = 0; $i < amount; $i++)
    {
       array_push($pax, array('paxType' => $type));
    }
    return $pax;
}  

$RoomsLength = 1;//count($_POST['Rooms']);
$Rooms = array();

//iterate over all rooms
for ($i = 0; $i < $RoomsLength ; $i++)
{
    $Rooms[$i] = array();

    if ( count($Adults) > 0)
    {
        //use a function to add adults to room
        array_push($Rooms[$i] , addPaxType('Adults', count($Adults)));
    }
    if (count($Childs) > 0)
    {
        array_push($Rooms[$i], addPaxType('Childs', count($Childs)));
    }
} 

      $filters = array();
      $filters[] = array("filterType" => "hotelStar", "filterValue" => "3", "4", "5");

      $filters[] = array("filterType" => "resultLimit", "filterValue" => "7");

      // make getAvailableHotel request (start search)
      $checkAvailability = $client->getAvailableHotel("gfdgdfgVNhTzA4MVZ3Y2hjTkt3QXNHSXZRYUZOb095Qg==", "RHMK", "2015-03-30", "2015-04-12", "EUR", "RO", "false", $rooms, $filters);
  }
  catch (SoapFault $exception) {
      echo $exception->getMessage();
      exit;
  }
Razvan Baba
  • 155
  • 9
  • What variables are you sending to the server through that HTML form? – acontell Dec 27 '14 at 16:42
  • i have modified the answer text. Please check. Thank you. – Razvan Baba Dec 27 '14 at 16:52
  • You appear to have asked the same question three times now. Each time with less detail then the previous. [1](http://stackoverflow.com/questions/27669265/translate-html-form-request-to-php-array) [2](http://stackoverflow.com/questions/27675114/can-i-send-soap-request-from-html-form) [3](http://stackoverflow.com/questions/27686210/how-to-send-json-request-from-html-form-and-receive-in-soap) – Quentin Dec 29 '14 at 09:38

2 Answers2

1

You can get an array setting in the name input method on the html form post

<br />Room: <input type="text" **name="somearray[]"** required/></br>

After that you can do some like this

$room=$_POST['somearray'];

forgive my bad English!

J_E_Roseto
  • 11
  • 1
  • Thanks. My form is working fine with the text imput fields. I dont know how to translate the selectors value into a php array as in description. – Razvan Baba Dec 27 '14 at 17:06
1

You need a for lus for this. Based upon the data on this page. I cannot define in which rooms the children and adults are and the age of the children based upon the supplied data. I can however show you an attempt to make such an array.

function addPaxType($type = null, $amount = 0)
{
    $pax = array();
    for ($i = 0; $i < amount; $i++)
    {
       array_push($pax, array('paxType' => $type));
    }
    return $pax;
}  

$RoomsLength = count($_POST['Rooms']);
$Rooms = array();

//iterate over all rooms
for ($i = 0; $i < $RoomsLength ; $i++)
{
    $Rooms[$i] = array();

    if ( count($Adults) > 0)
    {
        //use a function to add adults to room
        array_push($Rooms[$i] , addPaxType('adult', count($Adults)));
    }
    if (count($Childs) > 0)
    {
        array_push($Rooms[$i], addPaxType('child', count($Childs)));
    }
}   

When two rooms are selected and two adults this will output:

 $Rooms[0] --> [ [paxType => adult], [paxType => adult] ];
 $Rooms[1] --> [ [paxType => adult], [paxType => adult] ];
Mouser
  • 13,132
  • 3
  • 28
  • 54
  • How do you mean? Do you want a function wrapper? – Mouser Dec 27 '14 at 23:10
  • Yes. I have tried the javascript wrapper and php but has errors. – Razvan Baba Dec 27 '14 at 23:13
  • @RazvanBaba corrected some errors in the code. My humble excuses. – Mouser Dec 27 '14 at 23:18
  • This code is pure PHP and needs to be in the PHP part of the form handler. Between `` – Mouser Dec 27 '14 at 23:20
  • Thanks, i have tested and seems that something is wrong, i get : Incorrect number of rooms in XML request (minimum: 1 room, maximum: 5 rooms), Please let me know if i do something wrong..( check question area ) – Razvan Baba Dec 27 '14 at 23:43
  • Please remove the `1` at `$Roomslength` and uncomment the `$_POST` – Mouser Dec 27 '14 at 23:49
  • seems like the webservices dont recognise the php response so it can perform a search – Razvan Baba Dec 28 '14 at 00:06
  • Most SOAP webservices require xml input, not a PHP array as input. Read into this: it could help you further: http://stackoverflow.com/questions/1397036/how-to-convert-array-to-simplexml. You need to find the instructions to make a good SOAP-call to that webservice. – Mouser Dec 28 '14 at 00:10
  • Thanks Mouser for your time. Really appreciate. Seemn like i need to start digging and learn more. :) I am truggling with this for several days :(. Please check a bit at the example provided in the document from (www.hotelspro.com/xf_4.0/HotelsPro_XML_booking_system_4_1.doc ) maybe you know to link the form to the page so it can return some response based on the input request. – Razvan Baba Dec 28 '14 at 00:21
  • Sorry, I can not help `xslt`- and `SOAP`-requests are not my field of expertise. Continue coding and if get stuck, post the relevant coding into a new question. There will be enough `SOAP` and `XSLT` experts here. – Mouser Dec 28 '14 at 00:24
  • Hi Mouser, i have tried with the below code but its returning me only one room and 1 adult. $Adults = intval($_POST["Adults"]); $rooms = array(); for ($x = 0; $x < $Adults; $x++) { array_push($rooms,array("paxType" => "Adult")); } – Razvan Baba Dec 29 '14 at 10:32