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;
  }
3
  • What variables are you sending to the server through that HTML form? Commented Dec 27, 2014 at 16:42
  • i have modified the answer text. Please check. Thank you. Commented Dec 27, 2014 at 16:52
  • You appear to have asked the same question three times now. Each time with less detail then the previous. 1 2 3 Commented Dec 29, 2014 at 9:38

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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] ];

11 Comments

How do you mean? Do you want a function wrapper?
Yes. I have tried the javascript wrapper and php but has errors.
@RazvanBaba corrected some errors in the code. My humble excuses.
This code is pure PHP and needs to be in the PHP part of the form handler. Between <?php and ?>
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 )
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.