制作搜索表单以使用http api进行搜索
我对这件事不熟悉。我正在尝试创建一个搜索表单,它允许通过http api搜索数据库并在网站上显示结果。呼叫需要授权:制作搜索表单以使用http api进行搜索,http,search,Http,Search,我对这件事不熟悉。我正在尝试创建一个搜索表单,它允许通过http api搜索数据库并在网站上显示结果。呼叫需要授权: $headers = array ('headers' => array( 'Authorization' => 'bearer' . $token , 'Content-type' => 'application/json',
$headers = array ('headers' => array(
'Authorization' => 'bearer' . $token ,
'Content-type' => 'application/json',
'Accept' => 'application/json'));
我的搜索表单如下所示:
<form method="GET" accept="application/json" action="https://example.xx/api/v1/products?page=1&size=5&direction=asc&search=value">
<input type="text" name="search" size="40" maxlength="256" value="" placeholder="testsearch">
<input type="submit" name="search_button" value="Search">
</form>
在浏览器地址字段中,我看到:
https://example.xx/api/v1/products?search=testvalue&search_button=Search
显然,授权被忽略,url显示我已经离开了我的网站
我是否必须使用action=“somephp.php”来实现这一点?
如何从表单中授权呼叫并在网站中显示响应?
非常感谢。theo感谢德国wordpress论坛,我找到了答案—— 表格:
<form method="post" id="api-result-searchform" action="">
<input type="text" class="search" placeholder="<?php echo esc_attr_x( 'Author?', 'placeholder' ) ?>" value="" name="searchauthor" id="s" title="api-search" />
<input class="button"type="submit" name="search_button" value="Search">
</form>
<form method="post" id="api-result-searchform" action="">
<input type="text" class="search" placeholder="<?php echo esc_attr_x( 'Author?', 'placeholder' ) ?>" value="" name="searchauthor" id="s" title="api-search" />
<input class="button"type="submit" name="search_button" value="Search">
</form>
<?php
$searchterm = $_POST['searchauthor'];
$url = 'https://example.de/api/v1/product?search=ti=' . $searchterm;
$response = wp_remote_get($url, $headers);
//etc.