确定从WordPress / PHP中动态创建的表单中选择的项目

After a better understanding of the code after some research I am now asking a further question.

I have a dynamically generated form, the code is shown below:

function prepareBlocksHtml_()
{
    $class = new Graffitiwall();
    $data = $class->getBlocks();

    /* Get the current orderID */
    $orderid = get_last_order_id();

    echo "The Latest Order ID is ";  
    echo $orderid;  


    $html = '<table width="100%" border="0">
  <thead>
    <tr>
      <th>Block</th>
      <th>OrderID</th>
      <th>Status</th>
      <th>Image</th>
      <th>Destination</th>
      <th>Expiry</th>
      <th>Options</th>
    </tr>
    </thead>';
    $count = 1;
    if(count($data) == 0)
    {
        return "<div class='alert alert-warning' >Your blocks are not active yet, or you have not purchased any blocks yet.</div>";
    }
    foreach($data as $block)
    {

        if($block->status == 0)
        {
            $block->status = "Pending Approval";
        }
        else
        {
            $block->status = "Active";
        }

        $fields = array();
        $fiedls['orderid'] = $block->orderid;
        $fields['destination'] = $block->destination;
        $fields['tagline'] = $block->tagline;
        $fields['image'] = $block->image;
        $fields['id'] = $block->id;

        $fields = json_encode($fields);

        $settings = $block->permissions;
        $html .= '<tr id=block_"'.$block->id.'">';

        /* add order ID PC 14-8-2018 */


        $html .= '<td>'.$count.'</td>';
        $html .= '<td>'.$block->orderid.'</td>';
        $html .= '<td>'.$block->status.'</td>';
        $html .= '<td><img style="max-width: 61px" class="img-responsive " src="'.$block->image.'" </td>';
        $html .= '<td>'.$block->destination.'</td>';
        $html .= '<td>'.$block->expiry.'</td>';


        $html .= '<td><button class="edit" onclick="showModal(\''.$block->userid.'\',\''.base64_encode($settings).'\',\''.base64_encode($fields).'\')">Edit</button></td>';

        $html .= '</tr>';
        $count ++;

    }

    $html .='</table>';
    return $html;

}

The code grabs data from a table and shows a list of orders and the data associate with each one. Then the code calls a ShowModal function that sends the user and data as well for each row, with an EDIT button highlighted here:

$html .= '<td><button class="edit" onclick="showModal(\''.$block->userid.'\',\''.base64_encode($settings).'\',\''.base64_encode($fields).'\')">Edit</button></td>';

This calls a function in my main.js file called showModal as shown here

function showModal(user,settings,data)
{
    jQuery("#uploadBox, #selectBox, #labelurl, #url").hide();

    jQuery("#editListing").modal();

   settings = JSON.parse(atob(settings));
   data = JSON.parse(atob(data));


   if(typeof(settings.custom_logo) !== 'undefined' && settings.custom_logo === true)
   {
       jQuery("#uploadBox").show();
   }
   if(typeof(settings.badge) !== 'undefined' && settings.badge === true)
   {
       jQuery("#selectBox").show();
   }
   if(typeof(settings.link) !== 'undefined' && settings.link === true)
   {
    jQuery("#labelurl, #url").show();
   }


   // this is where data is passed to the showModal
   // add in orderid mapping to ordid

   jQuery("#ordid").val(data.orderid);

   jQuery("#url").val(data.destination);
    jQuery("#tooltip").val(data.tagline);
    jQuery("#rid").val(data.id);
    jQuery("#blockImage").attr('src',data.image);

    jQuery('#editListing').modal('show');


}

Then this calls the code for showing the form:

<div id="editListing" class="modal fade" role="dialog">
        <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Edit Block</h4>

                </div>
                <div class="modal-body">
                    <form id="editingForm" enctype="multipart/form-data">

                        <!-- Added label for Order ID -->
                        <label id="labelorderid" class="" style="display: none">Order ID</label>
                        <input id="ordid" name="ordid" style="display: none;" class="form-control" placeholder="Order ID" />

                        <label id="labelurl" class="" style="display: none">Destination Url with http://</label>
                        <input id="url" name="url" style="display: none;" class="form-control" placeholder="Destination URL with http://" />

                        <label class="">Strapline</label>
                        <input id="tooltip" name="tooltip" class="form-control" placeholder="Strapline" />
                        <label class="">Images</label>
                        <div id="uploadBox" class="row" style="display: none;">

                            <div class="col-lg-2">
                                <img id="blockImage" src="" class="img-responsive zoom" />
                            </div>
                            <div class="col-lg-10">
                                <input id="imageFile" name="imageFile" type="file" class="">
                            </div>
                        </div>

                        <!-- Changed the value of selection - starting at 0 instead of 1 -->

                        <div id="selectBox" class="row" style="display: none">
                            <p>Stickers are currently free to change</p>
                            <select id="stickers">
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/001.jpg' value='0'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/002.jpg' value='1'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/003.jpg' value='2'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/004.jpg' value='3'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/005.jpg' value='4'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/006.jpg' value='5'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/007.jpg' value='6'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/008.jpg' value='7'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/009.jpg' value='8'>
                                <option data-img-src='/wp-content/plugins/graff/public/images/stickers/010.jpg' value='9'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/011.jpg' value='10'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/012.jpg' value='11'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/013.jpg' value='12'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/014.jpg' value='13'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/015.jpg' value='14'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/016.jpg' value='15'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/017.jpg' value='16'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/018.jpg' value='17'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/019.jpg' value='18'>
                                <option data-img-src=../wp-content/plugins/graff/public/images/stickers/020.jpg' value='19'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/021.jpg' value='20'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/022.jpg' value='21'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/023.jpg' value='22'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/024.jpg' value='23'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/025.jpg' value='24'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/026.jpg' value='25'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/027.jpg' value='26'>
                                <option data-img-src='../wp-content/plugins/graff/public/images/stickers/028.jpg' value='27'> 

                            </select>

                        </div>

                        <input id="rid" name="rid" type="hidden">
                    </form>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="saveBlockData()">Save</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>

        </div>
    </div>

I noticed how the ShowModal function is passing parameters to the form generation code so I included the OrderID.

However the code I have added to the form to display the orderid is not working. I just copied and pasted from one of the others and modified it. It does not display the label of the input box.

How can I display the value of the OrderID correctly? If I can can get that working I can pass it to the function that updates the table.

duanbimo7212
duanbimo7212 发生在我们最好的人身上。作为拼写错误投票结束。
大约 2 年之前 回复
duangouyan3328
duangouyan3328 开溜。谢谢帕特里克Q.错字造成了巨大的差异。从那里形式工作,然后我能够将它传递给更新功能来更新表。谢谢。令人惊讶的是,你可以长时间盯着某个东西看不到它。
大约 2 年之前 回复
duanhao4156
duanhao4156 $fiedls['orderid']=$block->orderid;你有一个错字。这将是一个很好的起点。我也没有看到ordid输入元素被显示的任何地方(它最初隐藏着display:none;)虽然我可能只是错过了。
大约 2 年之前 回复
dora12345678
dora12345678 代码由朋友交给我,因为他们的开发人员在没有移交的情况下离开了。已经做了很多修复,现在尝试添加这个额外的功能。我试图了解为什么ordid标签/字段在其他项目时没有显示在表单中。表单是从前一个开发人员所做的ShowModal函数调用的,我试图修改以包含orderid。
大约 2 年之前 回复
dqlm80253
dqlm80253 “我对showModal函数不太熟悉”这不是你写的函数吗?那它从哪里来?它不是原生的Javascript函数(不管怎么说都没有)。我认为看到这个函数和saveBlockData()可能是最重要的事情。你的前两个代码块非常无关紧要。
大约 2 年之前 回复
dongxun1142
dongxun1142 我对showModal函数不太熟悉,但该行似乎将参数传递给表单,例如当前的用户标识和字段。我可以传递一个附加参数,参考哪个EDIT按钮被点击,然后访问相关的orderid?
大约 2 年之前 回复
dongxie3681
dongxie3681 是的,这是很多。我不确定如何关注它。主要问题是在prepareblocks函数中,有一个循环在表中创建一行。每行代表一个订单。$html。='<td><buttonclass=“edit”onclick=“showModal(\''。$block->userid。'\',\''。base64_encode($settings)。'\',\'”.base64_encode($字段)。'\')“>修改</按钮></TD>';每行末尾都有一个编辑按钮。我想唯一地识别用户按下哪个按钮,以便我知道在编辑后保存哪个订单。
大约 2 年之前 回复
douda5706
douda5706 老实说,我甚至没有在中途做到这一点。你有什么办法可以让它更专注吗?
大约 2 年之前 回复

1个回答

Error in code due to typo.

$fiedls['orderid'] = $block->orderid;

should be

$fields['orderid'] = $block->orderid;

立即提问
相关内容推荐