Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用HTTP GET从外部API自动填充表单选择字段_Php_Ruby On Rails_Wordpress_Forms_Get - Fatal编程技术网

Php 使用HTTP GET从外部API自动填充表单选择字段

Php 使用HTTP GET从外部API自动填充表单选择字段,php,ruby-on-rails,wordpress,forms,get,Php,Ruby On Rails,Wordpress,Forms,Get,我正在尝试从WordPress站点链接一个HTML/PHP表单,以便与使用Ruby on Rails构建的外部数据库通信。我被告知这个数据库有一个完整的API 完整表单有一些其他标准文本字段等,但为了提供基本概述,用户可以在下面的“make_”字段中选择一个汽车品牌。然后,这将与数据库的API通信,以填写下一个选择“inquest_model”的选项,然后在此基础上,将有另一个调用填充“inquest_year”字段 <form accept-charset="UTF-8" action=

我正在尝试从WordPress站点链接一个HTML/PHP表单,以便与使用Ruby on Rails构建的外部数据库通信。我被告知这个数据库有一个完整的API

完整表单有一些其他标准文本字段等,但为了提供基本概述,用户可以在下面的“make_”字段中选择一个汽车品牌。然后,这将与数据库的API通信,以填写下一个选择“inquest_model”的选项,然后在此基础上,将有另一个调用填充“inquest_year”字段

<form accept-charset="UTF-8" action="http://runbikestop.com/inquests" class="new_inquest" id="new_inquest" method="post">

      <div class="field" id="make_field">
         <label for="inquest_make">Make <span class="please-wait">please wait</span></label>
         <select id="inquest_make" name="inquest[make]"><option value="">Please select</option>
           <option value="ABARTH">ABARTH</option>
           <option value="ALFA ROMEO">ALFA ROMEO</option>
           <option value="AUDI">AUDI</option>
           <!--(there are 100 or so more options here...)-->
        </select>
       </div>

       <div class="field">
         <label for="inquest_make">Model <span class="please-wait">please wait</span></label>
         <select id="inquest_model" name="inquest[model]">
           <option> </option>
         </select>
       </div>

       <div class="field" id="year_field">
          <label for="inquest_make">Year <span class="please-wait">please wait</span></label>
          <select id="inquest_year" name="inquest[year]">
           <option> </option>
         </select>
       </div>

        <input id="inquest_gclid_code" name="inquest[gclid_code]" type="hidden" />
        <input id="inquest_webpage_url" name="inquest[webpage_url]" type="hidden" />

       <div class="actions">
         <input name="commit" type="submit" value="Submit" />
       </div>
</form>

另一位开发人员建议不要使用javascript API调用,而是建议使用HTTP get请求/调用。。。?我只是不知道最好的办法是什么,让这一切工作,所以如果有人能给我指出正确的方向,将不胜感激

我建议您使用Javascript来应对这一挑战。我不确定您在前端代码中使用了哪些库,但是使用jqueryajax工具可以帮助您轻松地使用rorapi

制作一个小包装器或SDK来与API通信,这样您就可以将应用程序逻辑与从API获取数据所需的接口解耦

window.API=window.API | |{}; API.getModels=functionmodels{ 变量url=http://runbikestop.com/api/v1/cars/models?callback=?; 返回$.getJSON url,模型; };
curl -i -H "Accept: application/json"  http://runbikestop.com/api/v1/cars/models?makes=ALFA+ROMEO 
curl -i -H "Accept: application/json" "http://runbikestop.com/api/v1/cars/car_years?makes=ALFA+ROMEO&models=156"