0

I am tryiong to integrate a XML API solution for Hotel Booking, and i want to use JSON to send onject to php so the system can return me the responses. The form is :

<form action="https://www.bookingassist.ro/test/html/hotel-list-view.php" method="post">
<label>Destinatie</label>
<input type="text" value="Oras" name="City" id="autocomplete" placeholder="Oras sau regiune" />
<label>Check In</label>
<input type="text" name="In" value="AAAA/LL/ZZ" class="input-text full-width" placeholder="yyyy/mm/dd" />
label>Check Out</label>
<input type="text" name="Out" value="AAAA/LL/ZZ" class="input-text full-width" placeholder="yyyy/mm/dd" />
<label>Camere</label>">
 <select name="RoomsNR" class="full-width">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label>Adulti</label>
<select name="Adults" class="full-width">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<label>Copii</label>
<select name="Kids" class="full-width">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
 <option value="3">3</option>
<option value="4">4</option>
 </select>
<button type="submit">CAUTA</button>
</form>

For the city, in and out i sent them using post.

And i need to receive the information in php as the below: -And example with 2 rooms selected and 4 adults

  // First Room
  $rooms[] = array(array("paxType" => "Adult"));

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

I have tried to send the values using post and create some php rules by its not working as it should. Several people adiced me to do this with JSON, but i have no ideea how to do this. Of helps the Instruction for this API system can be found at : www.hotelspro.com/xf_4.0/HotelsPro_XML_booking_system_4_1.doc

4
  • Your form doesn't have inputs for multiple rooms. Where are all those values coming from? Can't you make the arrays in PHP using the regular inputs from the form? Commented Jan 3, 2015 at 2:49
  • Gather the form data and put it into javascript object. Then use JSON.stringify() to get the object as string. Store this string in a hiddenfield and post it to the server via the form. On server side you can use json_decode($_POST['hiddenfield_json']) to receive the values as object (or array if you want) Commented Jan 3, 2015 at 2:52
  • i have tried using some pho rules, but it doest work as it should. Example : if i select 2 rooms and 4 adults it returns the response for 2 room each room has 4 adults, instean the correct andwer with two rooms each room with 2 adults( i want to split the adults/kids number into the rooms numbers Commented Jan 3, 2015 at 2:53
  • @Tyr , ill be gratfull if you can help me with an example code. I dont have any clue how to do this. I know bit of php only. Commented Jan 3, 2015 at 2:55

1 Answer 1

1

Several people adiced me to do this with JSON

Well, might be they did but you should keep things much more separated here if you're looking to solve this with more ease.

What you do with the HTML form and how you submit the data (either via the classic submit button resulting in a HTTP POST request to the server or by using some javascript code that takes the form data and creates a HTTP POST request to the server) is not so much an issue on how to interact with the remote API.

Take this sentence of yours for example in which you describe your problem:

I have tried to send the values using post and create some php rules by its not working as it should.

Given that there are two major parts in the application (most likely there are three, next to input (1) and processing (2) there is also output (3)), you have to locate the where the problem occurs first.

For example: The input UI/routines might not yet be 100% perfect (hat is in input (1)), but creating the wrong intermediate data formats in processing (2) does already count as an error on it's own. It's not that a possible wrong input from (1) is the problem, but that processing (2) is not able to detect that.

So now looking in input (1) to solve a problem in processing (2) is not often working well, because too often you're looking at the wrong place.

So first mock the input (just set the variables as you need them) and check if interacting with the remote API works as expected.

This should also ensure that you don't get distracted only because somebody shipped just another new term to you which only creates more question marks.

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

Comments

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.