一次从多个文本区域插入内容

时间:2018-07-24 10:51:50

标签: javascript php html mysql ajax

我有两个div,每个div都包含自己的tinymce编辑器实例和隐藏的输入值:

    <form method="post">
    <div class="col-lg-12 fullWidth" id="full">
        <input type="hidden" name="fullWidth" value="">
        <div class="fullContent" style="background-color: white; height: 100%;">
                <input type="hidden" name="panel" value="1">
              <textarea class="original" id="mytextarea3" name="fullText">Some Text Here</textarea><!--I want to save this content along with panel_type_id = 1-->
              <input type="submit" value="Save Content">
        </div>
    </div>

    <div class="col-lg-12 halfWidth" id="half">
        <input type="hidden" name="halfWidth" value="">
        <div class="halfContent" style="background-color: white; height: 100%;">
                <input type="hidden" name="panel" value="2">
              <textarea class="original" id="mytextarea4" name="halfText">Some Text There</textarea><!--I want to save this content along with panel_type_id = 2-->
              <input type="submit" value="Save Content">

        </div>
    </div>
    </form>

如您所见,全角div的“面板”值应为“ 1”,半角div的“面板”值应为“ 2”。输入文本后,用户单击“保存”,将以一种小的形式输入页面标题,并从URL的“值”中捕获“ pageType”。效果很好,但是在提交表单时,我还想继承DIV文本区域上方的内容和“面板”值。这是表格,但我不知道如何处理多种面板类型和内容。

<form action="addPage.php" method="post">
<input type="hidden" name="pageType" value="<?php echo $value;?>">//This comes from the url value
<input type="hidden" name="panel" value="">
<input class="form-control" id="addTitle" name="addTitle"><!--Page Title-->
<input type="submit" name="Save Page">

问题是,当我现在调用addPage.php脚本以插入记录时,我不知道如何正确传递值,因此我无法添加一页记录(page_type_id和Title的$ value),但是然后在文本区域插入2条内容和面板记录。

在上面的代码中,这是我的预期插入内容:

pages

ID | Title    | page_type_id
1  | TitleNew | 1     /*this comes from $value*/

content

ID | Content
1  | Some Text Here
2  | Some Text There

panels

ID | panel_type_ID | page_id | content_id
1  |     1         |     1   |   1
2  |     2         |     1   |   2

这可以在所有3个表中一次插入,但是如果我可以为每个div设置多种面板类型,我该如何修改它以仍然插入一页记录,但可以成功处理多个面板和内容?

这是添加页面脚本

//This works for one record, but I think I need to add some kind of foreach or while into the insert for content and panel

//Insert Page
$title = $_POST['addTitle'];
$page_type = $_POST['pageType'];


$addpage = "
    INSERT INTO pages (title, page_type_id)
    VALUES ('$title','$page_type');
";
$mysqlConn->query($addpage)

$page_id = $mysqlConn->insert_id;

foreach(//panel and content){
//Insert Content
$content = $_POST['page_content'];

$addContent = "
    INSERT INTO content(content)
    VALUES('$content');
";

$mysqlConn->query($addContent);

$cont_id = $mysqlConn->insert_id;

//Insert panel(s)
$panelID = $_POST['panelType'];
$addPanel = "
    INSERT INTO panels(panel_type_id, page_id, cont_id)
    VALUES ('$panelID', '$page_id', '$cont_id');
";
$mysqlConn->query($addPanel);

}

0 个答案:

没有答案