翻译HTML表单请求的PHP数组 [英] Translate HTML form request to php array

查看:94
本文介绍了翻译HTML表单请求的PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3选择器的HTML表单:

  A。房间 - > 1,2,3,4,5,6
湾成人 - > 1,2,3,4,5,6
C。蔡尔兹 - > 0,1,2,3,4,5

这是我需要得到看起来像PHP数组:
例1房与2名成人

  $房[] =阵列(阵列(paxType=>中成人),阵列(paxType=>中成人));

例2房(一间是两个大人和2名成人的第二个房间SI
一个孩子

  $房[] =阵列(阵列(paxType=>中成人),阵列(paxType=>中成人));
$房[] =阵列(阵列(paxType=>中成人),阵列(paxType=>中成人),阵列(paxType=>中的孩子,年龄=&GT 8));

这是我从形式接收的变量是如下:

  $ =城$ _ POST ['市']; - 文本
$ CHECKIN = $ _ POST ['签']; - 文本(日期)
$结帐= $ _ POST ['结账']; - 文本(日期)
$客房总数= $ _ POST ['房间']; - 选择器(1,2,3,4,5,6)
成人$ = $ _ POST ['成人']; - 选择器(1,2,3,4,5,6)
$童车= $ _ POST ['柴尔兹']; - 选择器(0,1,2,3,4,5)

形式是文字和日期输入字段workink罚款。
我怎么能翻译的html表单请求进入一个波夫样子PHP数组。
感谢您的时间。

整个code是:

  //创建SOAP客户端对象
  $客户端=新SoapClient的(http://www.bookingassist.ro/test/book.wsdl,阵列('跟踪'=> 1));  尝试{
      功能addPaxType($型= NULL,$金额= 0)
{
    $旅客=阵列();
    为($ I = 0; $ I<金额; $ I ++)
    {
       array_push($ PAX,阵列('paxType'=> $型));
    }
    返回$ PAX;
}$ RoomsLength = 1; //计数($ _ POST ['房间']);
$客房总数=阵列();//遍历所有客房
为($ I = 0; $ I< $ RoomsLength; $ I ++)
{
    $房型[$ i] =阵列();    如果(计数($名成人)大于0)
    {
        //使用函数成年人加入到房间
        array_push($房型[$ i],addPaxType('成人',计数($名成人)));
    }
    如果(计数($童车)0)
    {
        array_push($房型[$ i],addPaxType('蔡尔兹',计数($童车)));
    }
}      $滤镜阵列=();
      $滤波器[] =阵列(过滤式=>中hotelStar,filterValue=>中3,4,5);      $滤波器[] =阵列(过滤式=>中RESULTLIMIT,filterValue=>中7);      //使getAvailableHotel请求(开始搜索)
      $ checkAvailability = $客户端 - > getAvailableHotel(gfdgdfgVNhTzA4MVZ3Y2hjTkt3QXNHSXZRYUZOb095Qg ==,RHMK,手绘POP练习,2015年4月12日,欧元,RO,假,$室,$过滤器);
  }
  赶上($的SOAPFault除外){
      回声$&与异常GT;的getMessage();
      出口;
  }


解决方案

您需要一个的逻辑单元这一点。基于此页面上的数据。我不能定义在其中间的儿童和成人是与根据所提供的数据的儿童的年龄。不过,我可以告诉你一个试图做这样一个数组。

 函数addPaxType($型= NULL,$金额= 0)
{
    $旅客=阵列();
    为($ I = 0; $ I<金额; $ I ++)
    {
       array_push($ PAX,阵列('paxType'=> $型));
    }
    返回$ PAX;
}$ RoomsLength =计数($ _ POST ['房间']);
$客房总数=阵列();//遍历所有客房
为($ I = 0; $ I< $ RoomsLength; $ I ++)
{
    $房型[$ i] =阵列();    如果(计数($名成人)大于0)
    {
        //使用函数成年人加入到房间
        array_push($房型[$ i],addPaxType('成人',计数($名成人)));
    }
    如果(计数($童车)0)
    {
        array_push($房型[$ i],addPaxType(孩子,计数($童车)));
    }
}

在两个房间的选择和两个大人这将输出:

  $房型[0]  - > [paxType =>成人],[paxType =>成人]];
 $房型[1] - > [paxType =>成人],[paxType =>成人]];

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;
  }

解决方案

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

这篇关于翻译HTML表单请求的PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆