dqr91899 2012-06-06 13:55
浏览 32
已采纳

从回显的表单值创建DOM

I have form, which builds a rather large output setup in various elements, based on how the form is filled out. I can post the whole code, but i think this makes it easier to understand, what I am trying to do.

Let's say I have form, with one input text field called 'notes'.

In this example, we pretend i have entered "Hello World!" in 'notes'.

When the form is posted, the value entered into 'notes' is echoed within some elements:

            <?php

            echo '<div class="bon" id="bon">';

            if (empty($_POST['notes'])) {
            // Echo nothing
            } else {
            echo '<div class="bonHr"></div>';
            echo '<div class="bonField">';
            echo '<span>' . nl2br($_POST['notes']) . '</span>';
            echo '</div>';
            }

            echo '</div>';

            ?>

And that is fine. Now I want to store the value in mySQL - I know how to do that. Problem is I want to store the value including the elements around it, into a mysql textfield.

So what I really want to store is everything the contains, in this case:

            <div class="bon" id="bon">
            <div class="bonHr"></div>
            <div class="bonField">
            <span>Hello World!</span>
            </div>
            </div>

How can I do this??

The reason why I need to do this, is that the output varies alot. So please help me to figure out how I can take a "dump" of the output, and throw it into mySQL...

  • 写回答

1条回答 默认 最新

  • douzhai1182 2012-06-06 14:04
    关注

    Just store your output in variable show it and save in database.

    <?php
    $output = "";
    $output .= '<div class="bon" id="bon">';
    
    if (empty($_POST['notes'])) {
    // Echo nothing
    } else {
    $output .= '<div class="bonHr"></div>';
    $output .= '<div class="bonField">';
    $output .= '<span>' . nl2br($_POST['notes']) . '</span>';
    $output .= '</div>';
    }
    
    $output .= '</div>';
    echo $output;
    
    //Save output to database
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题