从数组中POST多个值 - PHP

时间:2015-02-19 18:48:26

标签: javascript php jquery

我一直在尝试使用Image Picker使用PHP提取来自RSS Feed的多个选项。我能够在前端显示所有信息,甚至可以选择。问题是,当我在图像选择器的内部POST变量时,选项'不要传递给/insert.php。

我已经列出了下面的相关代码,包括文档中使用的Javascript for Image Picker。有人可以帮我识别我忽视或遗失的内容吗?我的脑袋只能在桌子上受到更大的冲击。感谢。

Image Picker JS

           $(document).ready(function () {
                    $("#selectBlog").imagepicker({
                    hide_select: true,
                    show_label: true,
                     selected:function(){
                  console.log($(this).val());

              }

                });

                var $container = $('.image_picker_selector');
                // initialize
                $container.imagesLoaded(function () {
                    $container.masonry({
                        columnWidth: 20,
                        itemSelector: '.thumbnail'
                    });
                });
            });

HTML / PHP         

    <select id="selectBlog" name="selectBlog[]" class="image-picker show-labels show-html" data-limit="2" multiple="multiple">

    <?php

        $rss = new DOMDocument();
        $rss->load('/rss.xml');
        $feed = array();
        foreach ($rss->getElementsByTagName('item') as $node) {
            $htmlStr = $node->getElementsByTagName('description')->item(0)->nodeValue;
            $html = new DOMDocument();        
            $html->loadHTML($htmlStr);
             //get the first image tag from the description HTML
             $img = $html->getElementsByTagName('img')->item(0)->getAttribute('src');
             $item = array (
              'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
              'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
              'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
              'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
              'image' => $img,
            );
            array_push($feed, $item);
          }


        $limit = 4;
        for($x=0;$x<$limit;$x++) {
          $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
          $link = $feed[$x]['link'];
          $description = $feed[$x]['desc'];
          $date = date('l F d, Y', strtotime($feed[$x]['date']));
          $img = $feed[$x]['image'];

    ?>

    <div class="col-md-3">
      <div class="well">
        <center>

         <option name="selectBlog[<?php echo $x ?>]" data-img-src="<?php echo $img ?>" value="<?php echo $img ?>" data-img-label="
          <br><br>
          <label for='blogTitle'>Blog Title</label>
          <input type='text' class='form-control' name='blogTitle[<?php echo $x ?>]' id='blogTitle' value='<?php echo $title ?>'>
          <label for='blogImg'>Blog IMG</label>
          <input type='text' class='form-control' name='blogImg[<?php echo $x ?>]' id='blogImg' value='<?php echo $img ?>'>
          <label for='blogUrl'>Blog URL</label>
          <input type='text' class='form-control' name='blogUrl[<?php echo $x ?>]' id='blogUrl' value='<?php echo $link ?>'>">
          </option> 

        </center>
      </div>
    </div>

    <?php } ?>


    </select>

    <button type="submit" class="btn btn-default pull-right">Send Email</button>

    </form>

1 个答案:

答案 0 :(得分:0)

看起来您的两个“选项”具有相同的名称和ID“blogUrl”。你可以删除它并再试一次吗?也许这会将值覆盖到它们中。

<强>更新

我猜代码应该是

<select id="selectBlog" name="selectBlog[]" class="image-picker show-labels show-html" data-limit="2" multiple="multiple">

<?php

    $rss = new DOMDocument();
    $rss->load('/rss.xml');
    $feed = array();
    foreach ($rss->getElementsByTagName('item') as $node) {
        $htmlStr = $node->getElementsByTagName('description')->item(0)->nodeValue;
        $html = new DOMDocument();        
        $html->loadHTML($htmlStr);
         //get the first image tag from the description HTML
         $img = $html->getElementsByTagName('img')->item(0)->getAttribute('src');
         $item = array (
          'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
          'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
          'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
          'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
          'image' => $img,
        );
        array_push($feed, $item);
      }


    $limit = 4;
    for($x=0;$x<$limit;$x++) {
      $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
      $link = $feed[$x]['link'];
      $description = $feed[$x]['desc'];
      $date = date('l F d, Y', strtotime($feed[$x]['date']));
      $img = $feed[$x]['image'];

?>
     <option data-img-src="<?php echo $img ?>" value="<?php echo $img ?>" data-img-label="
      <br><br>
      <label for='blogTitle'>Blog Title</label>
      <input type='text' class='form-control' name='blogTitle[<?php echo $x ?>]' id='blogTitle' value='<?php echo $title ?>'>
      <label for='blogImg'>Blog IMG</label>
      <input type='text' class='form-control' name='blogImg[<?php echo $x ?>]' id='blogImg' value='<?php echo $img ?>'>
      <label for='blogUrl'>Blog URL</label>
      <input type='text' class='form-control' name='blogUrl[<?php echo $x ?>]' id='blogUrl' value='<?php echo $link ?>'>">
      </option> 

<?php } ?>


</select>

这应该没问题。