繁体   English   中英

从数组中POST多个值 - PHP

[英]POST Multiple Values from an Array - PHP

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

我已经列出了下面的相关代码,包括文档中使用的Javascript for 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>

看起来您的两个“选项”具有相同的名称和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>

这应该没问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM