【问题标题】:form is not creating post variables表单没有创建帖子变量
【发布时间】:2023-03-12 11:57:01
【问题描述】:

我有一个表单,它没有创建帖子变量, 为什么是这样?代码如下。 函数 createMedewerkerList();不是问题 尝试删除那里使用的所有功能,但它没有工作,所以我猜它与这个布局有关

function writeHoursForm(){
echo '<form method="post" action="#">';

        echo '<div class="topWrapper">'; // open topwrapper
            echo '<div class="employeeData">'; // open employeedata
                echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
                    echo '<tr>';
                        echo '<td>Werknemer</td>';
                        echo '<td>';
                            if (permissiesUren(0,0,1,false)){
                                echo '<div class="ui-widget">';
                                echo createMedewerkerList();
                                echo '</div>';
                            }else{
                                echo $_SESSION['name'];
                                echo '<input name="medewerkerid" type="hidden" value="'.$_SESSION['id'].'">';
                            }
                        echo '</td>';   
                    echo '</tr>';
                    echo '<tr>';
                        echo '<td>Weeknummer</td>';
                        echo '<td><input name="week" type="text" value="'.$date1.'"></td>';  
                    echo '</tr>';
                    echo '<tr>';
                        echo '<td>Jaar</td>';
                        echo '<td><input name="jaar" type="text" value="'.$date2.'"></td>';
                    echo '</tr>';
                    echo '</table>';
            echo '</div>'; // close omployeedata
        echo '</div>'; // close topwrapper

        echo '<div class="urenBriefWrap">'; // open urenbriefwrap
            echo '<div class="urenBrief">'; // open urenbrief
                echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
                    echo '<tr>';
                        echo '<th>Projectnummer</th>';
                        echo '<th>Omschrijving</th>';
                        echo '<th>Uren<br>100%</th>';
                        echo '<th>Uren<br>125% </th>';
                        echo '<th>Uren<br>150% </th>';
                        echo '<th>Kilometers<br>auto zaak</th>';
                        echo '<th>Kilometers<br>auto prive</th>';
                        echo '<th>Reisuren</th>';
                    echo '</tr>';
                    echo '<tr>';
                        echo '<td width="139"><input name="projectnummer" type="text"></td>';
                        echo '<td width="358">geen data beschikbaar</td>';
                        echo '<td width="68"><input name="uren_100" type="text"></td>';
                        echo '<td width="68"><input name="uren_125" type="text"></td>';
                        echo '<td width="68"><input name="uren_150" type="text"></td>';
                        echo '<td width="91"><input name="kilometers_zaak" type="text"></td>';
                        echo '<td width="91"><input name="kilometers" type="text"></td>';
                        echo '<td width="83"><input name="reisuren" type="text"></td>';
                    echo '</tr>';
                echo '</table>';
            echo '</div>'; // close urenbrief
        echo '</div>'; // close topwrapper

        echo '<input class="submit" type="submit" name="submit" value="Verzenden">';
        echo '<input class="submit" type="submit" name="submit" value="Verzenden & nieuwe regel toevoegen">';
        if (permissiesUren(0,0,1,false)){
            echo '<input class="submit" type="submit" name="submit" value="Verzenden zonder tussencontrole">';
        }
    echo '</form>';
}

处理此表单的函数:

function urenRegisterParser(){
    if ($_SERVER['REQUEST_METHOD'] != 'POST'){
        writeHoursForm();
    }
    else if($_POST['submit'] == 'Verzenden & nieuwe regel toevoegen'){
        writeHoursToDB(false, $_POST);
        header('location: '.fullUrl().'urenregistratie/uren_invullen/?send=done');
    }
    else if($_POST['submit'] == 'Verzenden'){
        $NaamId = writeHoursToDB(false, $_POST);
        header('location: '.fullUrl().'urenregistratie/medewerkers/?NaamId='.$NaamId);
    }
    else if($_POST['submit'] == 'Verzenden zonder tussencontrole'){
         writeHoursToDB(true, $_POST);
        header('location: '.fullUrl().'urenregistratie/uren_invullen/?send=done');
    }
}

【问题讨论】:

  • 首先,去掉所有的echoes。不需要用echo打印静态内容。
  • 不要将action 设置为# 所做的只是跳转到一个锚点.. 将其留空或调用相同的页面来发布/重新加载
  • 我制作了所有的回声,因此更容易编辑;p 当我按下其中一个提交时,它不会创建任何帖子变量(接受变量的地方在 var_dump( $_POST): 数组 (0){})
  • aa 也许这是一个愚蠢的想法,但页面不能同时具有 GET 和 POST 变量吗? ;p
  • @DylanWestra 一个页面可以同时有 GET 和 POST 变量。 别笑了

标签: php html forms input


【解决方案1】:

这是一个答案...

不要将action 设置为# 所做的只是跳转到一个锚点.. 将其留空或调用同一页面发布/重新加载

<form method="post" action="">

或

<form method="post" action="<?php echo request.getRequestURL(); ?>">

【讨论】:

  • 你的意思是:
    ? ;p 已经尝试了 emty 操作,顺便说一句,确实有效
  • 不,&lt;?php echo request.getRequestURL(); ?&gt; 将在 action 参数中打印当前 url (http://...php)。您不想在action 参数中回显&lt;script&gt; 标记
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-02
相关资源
最近更新 更多