【问题标题】:Merge Search Inputs and Results into one input and one Result将搜索输入和结果合并为一个输入和一个结果
【发布时间】:2017-12-11 22:19:02
【问题描述】:

我制作了一个独特的脚本来替换“ebay 链接生成器”

我的 PHP 脚本有 3 个输入。每个输入都会做其他事情:

第一个:转发到易趣 第二个:将搜索到的产品(如您所见here)转换为另一个 eBay 链接 最后:将插入的自定义链接转换为另一个 eBay 链接

我希望它有一个“提交”按钮,当用户点击时,他会得到下面的 3 条信息(目前它显示与搜索的输入相关的一条信息)。

像这样:

我认为这与检测用户是否插入“搜索词”或以“http://ebay.com”开头的 URL 并转发到正确的 textarea 结果的 javascript 有关。

但是,我不知道如何防止第一个(直接搜索)输入直接进入 eBay,并在用户想要转发到 eBay 时提供单击选项。不知道这里应该考虑什么方法。

这里是 PHP (index.php) 代码:

<head>

    <!-- start direct ebay search script--> 
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(function() {
    $("#tfq2b").click(function() {
        if ($("#tfq2b").val() == "Search ebay Now"){
            $("#tfq2b").val(""); 
        }
    });
});
</script>
</head>

    <div style="width:800px; padding-left:300px;">

  <!-- start direct ebay search-->   
    <br><br><br><h2>Search Directly</h2>
    <div>
       <form method="get" action="http://rover.ebay.com/rover/1/711-53200-19255-0/1">

              <input type="text" id="tfq2b" class="tftextinput2" name="icep_uq" size="21" maxlength="120" value="">
              <input type='hidden' name='icep_ff3' value='9'>
              <input type='hidden' name='pub' value='5575165347'>
              <input type='hidden' name='toolid' value='10001'>
              <input type='hidden' name='campid' value='5337851510'>
              <input type='hidden' name='icep_sortBy' value='12'>
              <input type='hidden' name='icep_vectorid' value='229466'>
              <input type='hidden' name='kwid' value='902099'>
              <input type='hidden' name='mtid' value='824'>
              <input type='hidden' name='kw' value='lg'>

<input type="submit" value="search" class="btne">
        </form>
    </div>   
    <!-- end direct ebay search--> 


 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h2>Share ebay link</h2><br>
<input type=text style="font-size: 13px; font-family: tahoma,arial; font-weight: bold; color: #000000; BORDER: #555 1px solid ; BACKGROUND-COLOR: #FFF" input name="url"  size="20">

<input type="SUBMIT" name="submit" VALUE="Submit"> 
</form>

<?php include 'gen2.php'; ?>
</div>

<?php
if(isset($_POST['submit'])){
$url = $_POST['url'];
$name=array($url);
foreach ($name as $name) 

if (strlen($url) > 100) {
echo "<br><center><font color=\"red\">The field cannot contain more than 150 characters.</center>";

 Die();
}
}
?>
<br>
<center>
<form name="vini">
<a class="highlighttext" href="javascript:HighlightAll('vini.select1')">Select All</a><br>
<textarea id="p1" name="select1" rows=4 cols=100 style="font-family:tahoma;color:#555;border:1px dashed #ccc">
http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&pub=5575165347&toolid=10001&campid=5337851510&customid=&icep_uq=<?php echo $url ?>&icep_sellerId=&icep_ex_kw=&icep_sortBy=15&icep_catId=&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg
</textarea>
</form>

<?php
}
?>
</body>
</html>

这是我包含的第二个 PHP 文件 (gen2.php) 代码:

    <h2>Custom Link</h2>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

    <input type=text style="font-size: 13px; font-family: tahoma,arial; font-weight: bold; color: #000000; BORDER: #555 1px solid ; BACKGROUND-COLOR: #FFF" input name="url2"  size="20">

    <input type="SUBMIT" name="submit2" VALUE="Submit"> 
    </form>

    <?php
    if(isset($_POST['submit2'])){
    $url2 = $_POST['url2'];
    $name=array($url2);
    foreach ($name as $name) 

    if (strlen($url2) > 100) {
    echo "<br><center><font color=\"red\">The field cannot contain more than 150 characters.</center>";

     Die();
    }}
    ?>
    <br>
    <center>

    <form name="vini">
    <a class="highlighttext" href="javascript:HighlightAll('vini.select1')">Select All</a><br>

    <h2>Share ebay Custom link:</h2>
    <textarea id="p2" name="select1" rows=3 cols=100 style="font-family:tahoma;color:#555;border:1px dashed #ccc">
    http://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=4&pub=5575165347&toolid=10001&campid=5337851510&customid=&mpre=<?php echo $url2 ?>    
    </textarea> 

<br>
</form>

<?php
}
?>

我想将这三个中的一个变成 One 搜索输入,该输入将显示 One 搜索结果。第一个输入可以避免并且可以通过按钮左右使用。最后两个搜索输入很重要。

例如:
用户搜索单词“ocz vertex”,得到的结果为:

<textarea id="p1" name="select1" rows=4 cols=100 style="font-family:tahoma;color:#555;border:1px dashed #ccc">
http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&pub=5575165347&toolid=10001&campid=5337851510&customid=&icep_uq=<?php echo $url ?>&icep_sellerId=&icep_ex_kw=&icep_sortBy=15&icep_catId=&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg
</textarea>

如果他决定插入“http://ebay.com/”URL,他会得到如下结果:

<textarea id="p2" name="select1" rows=3 cols=100 style="font-family:tahoma;color:#555;border:1px dashed #ccc">
http://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=4&pub=5575165347&toolid=10001&campid=5337851510&customid=&mpre=<?php echo $url2 ?>    
</textarea> 

如果他想直接去 eBay,他会得到一个按钮,将他转到 eBay 产品页面。

直播可以看这里:Three Search and Convert Inputs

【问题讨论】:

标签: javascript php jquery html


【解决方案1】:

和我的兄弟我自己得到了它:

<?php

if(isset($_POST['submit'])) {
    $url = $_POST['url'];
    $name = array($url);
    foreach ($name as $name) {
        if (strlen($url) > 100) {
            echo "<br><center><font color='red'>The field cannot contain more than 150 characters.</center>";

            Die();
        }

    }
}
$token = "token";


if (count(explode('ebay.com',$url))>1) {
    $ebay_url = "http://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=4&pub=5575165347&toolid=10001&campid=5337851510&customid=&mpre=".urlencode($url)."";
}
else{
    $ebay_url = "http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&pub=5575165347&toolid=10001&campid=5337851510&customid=&icep_uq=".urlencode($url)."&icep_sellerId=&icep_ex_kw=&icep_sortBy=15&icep_catId=&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg";
}

$endpoint = "https://api-ssl.bitly.com/v3/shorten?access_token=".$token."&longUrl=".urlencode($ebay_url);
$json = json_decode(file_get_contents($endpoint), true);
echo $ebay_link = $json["data"]["url"];
?>

现在它正在工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    • 2013-07-25
    相关资源
    最近更新 更多