问题:PHP strip_tags &多维数组形式参数

发布于 2024-08-26 05:31:15 字数 6167 浏览 11 评论 0原文

我在从表单检索的文本输入中剥离标签以便在 checkout.php 中对它们执行某些操作时遇到问题。输入存储在多维数组中。

这是我的表单:

  echo '<form name="choose" action="checkout.php" method="post" onsubmit="return  validate_second_form(this);">';

        echo '<input type="hidden" name="hidden_value" value="'.$no_guests.'" />';

        if($no_guests >= 1){

            echo '<div class="volunteer">';
                echo '<fieldset>';
                    echo '<legend>Volunteer:</legend>';
                        echo '<label>Table:</label>';
                        echo '<select name="volunteer_table">';
                            foreach($tables as $t){
                                    echo '<option>'.$t.'</option>';
                                }
                        echo '</select><br><br>';
                        echo '<label>Seat number:</label>';
                        echo '<select name="volunteer_seat">';
                            foreach($seats as $seat){
                                    echo '<option>'.$seat.'</option>';
                                }
                        echo '</select><br><br>';
                        //echo '<br>';
                echo '</fieldset>';
            echo '</div>';

            for($i=0;$i<$no_guests;$i++){
                $guest = "guest_".$i;
                echo '<div class="'.$guest.'">';
                    echo '<fieldset>';
                        echo '<legend>Guest '.$i.':</legend>';
                            echo '<label>First Name:</label>';
                            echo '<input type="text" name="guest['.$i.']['.$first_name.']" id="fn'.$i.'">';
                            echo '<label>Surname:</label>';
                            echo '<input type="text" name="guest['.$i.']['.$surname.']" id="surname'.$i.'"><br><br>';

                            echo '<label>Date of Birth:</label> <br>';
                            echo '<label>Day:</label>';
                            echo '<select name="guest['.$i.'][dob_day]">';
                                for($j=1;$j<32;$j++){
                                    echo"<option value='$j'>$j</option>";
                                }
                            echo '</select>';

                            echo '<label>Month:</label>';
                            echo '<select name="guest['.$i.'][dob_month]">';
                                for($j=0;$j<sizeof($month);$j++){
                                    $value = ($j + 1);
                                    echo"<option value='$value'>$month[$j]</option>";
                                }
                            echo '</select>';

                            echo '<label>Year:</label>';
                            echo '<select name="guest['.$i.'][dob_year]">';
                                for($j=1900;$j<$year_limit;$j++){
                                    echo"<option value='$j'>$j</option>";
                                }
                            echo '</select> <br><br>';

                            echo '<label>Sex:</label>';
                            echo '<select name="guest['.$i.']['.$sex.']">';
                                echo '<option>Female</option>';
                                echo '<option>Male</option>';
                            echo '</select><br><br>';

                            echo '<label>Table:</label>';
                            echo '<select name="guest['.$i.']['.$table.']">';
                                foreach($tables as $t){
                                    echo '<option>'.$t.'</option>';
                                }

                            echo '</select><br><br>';
                            echo '<label>Seat number:</label>';
                            echo '<select name="guest['.$i.']['.$seat_no.']">';
                                foreach($seats as $seat){
                                    echo '<option>'.$seat.'</option>';
                                }
                            echo '</select><br><br>';
                            //echo '<br>';
                    echo '</fieldset>';
                echo '</div>';
            }
        }
        else{
            echo '<div id="volunteer">';
                echo '<fieldset>';
                    echo '<legend>Volunteer:</legend>';
                        echo '<label>Table:</label>';
                        echo '<select name="volunteer['.$table.']">';
                            foreach($tables as $t){
                                    echo '<option>'.$t.'</option>';
                                }
                        echo '</select><br><br>';
                        echo '<label>Seat number:</label>';
                        echo '<select name="volunteer['.$seat_no.']">';
                            foreach($seats as $seat){
                                    echo '<option>'.$seat.'</option>';
                                }
                        echo '</select><br><br>';
                        //echo '<br>';
                echo '</fieldset>';
            echo '</div>';
        }
        echo '<input type="submit" value="Submit form">';
    echo '</form>';

这是 checkout.php:

if(isset($_POST['guest'])){
foreach($_POST['guest'] as $guest){
    $guest['first_name'] = strip_tags($guest['first_name']);
    $guest['surname'] = strip_tags($guest['surname']);
}
//$_SESSION['guest'] = $guests;
}

I'm having problems stripping the tags from the textual inputs retrieved from my form so as to do something with them in checkout.php. The input is stored in a multi-dimensional array.

Here's my form:

  echo '<form name="choose" action="checkout.php" method="post" onsubmit="return  validate_second_form(this);">';

        echo '<input type="hidden" name="hidden_value" value="'.$no_guests.'" />';

        if($no_guests >= 1){

            echo '<div class="volunteer">';
                echo '<fieldset>';
                    echo '<legend>Volunteer:</legend>';
                        echo '<label>Table:</label>';
                        echo '<select name="volunteer_table">';
                            foreach($tables as $t){
                                    echo '<option>'.$t.'</option>';
                                }
                        echo '</select><br><br>';
                        echo '<label>Seat number:</label>';
                        echo '<select name="volunteer_seat">';
                            foreach($seats as $seat){
                                    echo '<option>'.$seat.'</option>';
                                }
                        echo '</select><br><br>';
                        //echo '<br>';
                echo '</fieldset>';
            echo '</div>';

            for($i=0;$i<$no_guests;$i++){
                $guest = "guest_".$i;
                echo '<div class="'.$guest.'">';
                    echo '<fieldset>';
                        echo '<legend>Guest '.$i.':</legend>';
                            echo '<label>First Name:</label>';
                            echo '<input type="text" name="guest['.$i.']['.$first_name.']" id="fn'.$i.'">';
                            echo '<label>Surname:</label>';
                            echo '<input type="text" name="guest['.$i.']['.$surname.']" id="surname'.$i.'"><br><br>';

                            echo '<label>Date of Birth:</label> <br>';
                            echo '<label>Day:</label>';
                            echo '<select name="guest['.$i.'][dob_day]">';
                                for($j=1;$j<32;$j++){
                                    echo"<option value='$j'>$j</option>";
                                }
                            echo '</select>';

                            echo '<label>Month:</label>';
                            echo '<select name="guest['.$i.'][dob_month]">';
                                for($j=0;$j<sizeof($month);$j++){
                                    $value = ($j + 1);
                                    echo"<option value='$value'>$month[$j]</option>";
                                }
                            echo '</select>';

                            echo '<label>Year:</label>';
                            echo '<select name="guest['.$i.'][dob_year]">';
                                for($j=1900;$j<$year_limit;$j++){
                                    echo"<option value='$j'>$j</option>";
                                }
                            echo '</select> <br><br>';

                            echo '<label>Sex:</label>';
                            echo '<select name="guest['.$i.']['.$sex.']">';
                                echo '<option>Female</option>';
                                echo '<option>Male</option>';
                            echo '</select><br><br>';

                            echo '<label>Table:</label>';
                            echo '<select name="guest['.$i.']['.$table.']">';
                                foreach($tables as $t){
                                    echo '<option>'.$t.'</option>';
                                }

                            echo '</select><br><br>';
                            echo '<label>Seat number:</label>';
                            echo '<select name="guest['.$i.']['.$seat_no.']">';
                                foreach($seats as $seat){
                                    echo '<option>'.$seat.'</option>';
                                }
                            echo '</select><br><br>';
                            //echo '<br>';
                    echo '</fieldset>';
                echo '</div>';
            }
        }
        else{
            echo '<div id="volunteer">';
                echo '<fieldset>';
                    echo '<legend>Volunteer:</legend>';
                        echo '<label>Table:</label>';
                        echo '<select name="volunteer['.$table.']">';
                            foreach($tables as $t){
                                    echo '<option>'.$t.'</option>';
                                }
                        echo '</select><br><br>';
                        echo '<label>Seat number:</label>';
                        echo '<select name="volunteer['.$seat_no.']">';
                            foreach($seats as $seat){
                                    echo '<option>'.$seat.'</option>';
                                }
                        echo '</select><br><br>';
                        //echo '<br>';
                echo '</fieldset>';
            echo '</div>';
        }
        echo '<input type="submit" value="Submit form">';
    echo '</form>';

here's checkout.php:

if(isset($_POST['guest'])){
foreach($_POST['guest'] as $guest){
    $guest['first_name'] = strip_tags($guest['first_name']);
    $guest['surname'] = strip_tags($guest['surname']);
}
//$_SESSION['guest'] = $guests;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花落人断肠 2024-09-02 05:31:15

您需要一个 & 来允许编辑对象。

foreach ($_POST['guest'] as &$guest)

You need an & to allow editing of the object.

foreach ($_POST['guest'] as &$guest)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文