亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在這 3 部分 PHP 注冊表單中調用會話數組中的數組

如何在這 3 部分 PHP 注冊表單中調用會話數組中的數組

PHP
繁星coding 2022-01-24 11:02:01
這是我在這里的第一個問題。請理解我是在自學,所以我所做的可能沒有任何意義。如果您對我為什么做某事有任何疑問,請隨時問我為什么,如果這不是正確的做法,請糾正我。I tried to make a 3 part form using $_SESSIONS to transfer over the data. 1) 我可以顯示除我在第 2 頁中所做的復選框之外的所有內容。我希望它顯示在最后:You are interested in: html, css如果我檢查 html 和 css 的復選框。我如何編寫代碼來做到這一點2) 我使用教程和谷歌的組合進行了編碼,雖然這些部分似乎有些工作,但我知道編碼風格是“新手”。如果您對如何提高可用性或編碼風格有任何建議,請告訴我。3) 當我刷新第 4 頁時,我看到我丟失了一些數據,因為我正在調用 session_destroy()。有什么辦法可以讓頁面顯示:“如果刷新,就會丟失數據”?我已經用谷歌搜索了我能做的讓我的項目大部分功能的東西,我只是停留在這部分。第 1 頁:<?php include_once('header.php'); ?>     <div id="main">        <div id="form">            <form action="page2.php" method="post">            <h1 style="font-family: Verdana"> Step 1: Contact Information </h1>              <?php                $style = 'margin: 15px 0px 15px 0px; padding-top: 5px; padding-bottom: 5px;';                required_text('name', 'name', 'Your Name', '80', 'Enter your name', $style);                $style = 'margin: 15px 0px 15px 0px; padding-top: 5px; padding-bottom: 5px;';                required_email('email', 'email', 'Your E-mail', '80', 'Enter your email', $style);                submit('Go To Step Two', 'primary-button'); ?>            </form>        </div>     </div>     <div id="footer" style="text-weight: bold; font-family: impact; color: white; margin-top: 50px; font-size: 25px; text-align: center;">          &copy; FocusedOnSomething     </div>  </div></div> </body></html>第2頁     <?php include_once('header.php') ?>     <?php         if (! empty ($_POST)) {            $_SESSION['name'] = $_POST['name'];            $_SESSION['email'] = $_POST['email'];         }     ?>     <?php print_r($_SESSION); ?>     <div id="main">        <div id="form">            <form method="post"action="page3.php">            <h1 style="font-family: Verdana"> Step 2 </h1>               <label class="checkbox-inline" for="interests">
查看完整描述

1 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

復選框的值存儲在 $_POST 中的一個數組中,您需要遍歷它們以獲取每個復選框的值:


// Initialise interest list as empty string

$interestList = '';


// Loop through checked interests

foreach($_POST['interests'] as $interest){

    // Add checked interest to string containing list of interests

    $interestList .= $interest . ', ';

}


// Remove last comma and space from interest list

if(strlen($interestList)) {

    $interestList = substr($interestList, 0, -2);

}

為了彈出有關刷新頁面的警告,您需要window.onbeforeunload在 javascript 中的某個位置使用。對此的瀏覽器兼容性是不完整的,可能無法為您提供所需的結果。


查看完整回答
反對 回復 2022-01-24
  • 1 回答
  • 0 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號