dou6495 2016-08-19 09:00
浏览 33
已采纳

通过隐藏的输入字段(值)将href作为字符串传递

I'm trying to pass some data through a hidden input field. I want every part to be wrapped by an anchor tag that links to the correct page. But when I send it the hidden values are displayed probably because sending an anchor tag through a value field is not allowed. How can I do this?

Code:

foreach($offertecr as $offerte1){
    if($offerte1['id'] != ''){
        $message .= '<a href="#">'.$offerte1['title'].'</a><br>';
    }
}

<input type="hidden" class="form-control-products" name="products" id="products" value="'.$message.'">

This results in the following:

enter image description here

I probably have to use javascript for this?

  • 写回答

1条回答 默认 最新

  • duanfei1975 2016-08-19 09:13
    关注

    You can use htmlspecialchars to convert the html tags into entities so that they can be properly displayed in your form.

    foreach($offertecr as $offerte1){
        if($offerte1['id'] != ''){
            $message .= htmlspecialchars('<a href="#">'.$offerte1['title'].'</a><br>');
        }
    }
    
    <input type="hidden" class="form-control-products" name="products" id="products" value="'.$message.'">
    

    When you obtain the posted information, you will have to convert the entities back into their corresponding tags using htmlspecialchars_decode.

    $html_value = htmlspecialchars_decode($posted_value);
    

    On the other hand, if you just want the information of the urls that point to the correct pages you can just skip the anchor tags and add only a comma separated value of the urls. You can later explode explode(',', $values) those values when you post the form to get the urls back.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题
  • ¥15 pic16F877a单片机的外部触发中断程序仿真失效
  • ¥15 Matlab插值拟合差分微分规划图论
  • ¥15 keil5 target not created
  • ¥15 C/C++数据与算法请教
  • ¥15 怎么找志同道合的伙伴
  • ¥20 如何让程序ab.eXe自已删除干净硬盘里的本文件自己的ab.eXe文件
  • ¥50 爬虫预算充足,跪巨佬
  • ¥15 滑块验证码拖动问题悬赏