繁体   English   中英

带有HTML的HTML选项表格

[英]HTML option form with php

目前,我对PHP和HTML有所了解,我的老师要求我将代码更改为下拉菜单,

到目前为止,我有这个

$html .='<option value="Argentina" <?php if($_POST['YourCountry']=="Argentina") echo "selected=selected"; ?>>Argentina</option>';

我不确定为什么它不起作用。 我正在尝试获取它,以便当有人在框中选择选项时,它将是插入查询中设置的值。 这是我的输入,我的老师要求我将其更改为选项一,但我不知道选项一

$html .='<input type="text" name="userCountry" id="userCountry" value="'.htmlentities(stripcslashes($_POST['userCountry'])).'" /><br/>'."\n";

完整代码==================================>

<?php

class HomeView extends View {
    protected function displayContent() {
        $html .= '<div id="pageinfo">'."\n";
        $html .= '<h2>'.$this -> pageInfo['pageHeading'].'</h2>'."\n";
        $html .= '</div>'."\n";
            if($_POST['register'] == "Submit") {
            //validate the form



            $vresult = $this -> model -> validateRegisterUser();


            //Check ALL okay
                 if ($vresult['ok'] == true) {
                //Call database


                            if ($this -> model -> register()) {
                                $htmt .='<div id="space">'."\n";
                                $html .='<div id="userreg">'."\n";
                                $html .='<p> User registered successfully<p>'."\n";
                                $html .= '<p>Please login '.$_POST['userName'].'</p>'."\n";
                                $html .='<img src ="optimized/images/joined.jpg" alt="welcome new member"/>'."\n";

                                $html .='</div>'."\n";
                                $html .='</div>'."\n";
                                    } else {

                                $html .='<div id="space">'."\n";
                                $html .='<img src ="optimized/images/failed.jpg" alt="failed to create new member"/>'."\n";
                                $html .= '<p> User creation failed. Please try again <p>'."\n";
                                $html .='</div>'."\n";
                            }        
                        return $html;
                }   
            }
            $html .='<div id="register">'."\n";

                $html .='<img src="optimized/images/rg.jpg" alt="registerimage"/>'."\n";
                $html .='<form method="post" action="'.$_SERVER['REQUEST_URI'].'" onSubmit="return confirm("Are you sure?");">'."\n";
                    $html .='<fieldset>'."\n";
                        $html .='<legend>'.'New Members Form'.'</legend>'."\n";
                        $html .='<label for="username">Username: </label><br/>'."\n";
                        $html .='<input type="text" name="userName" id="userName" value="'.htmlentities(stripcslashes($_POST['userName'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userNameMsg'].'</div>'."\n";
                        $html .='<label for="userFName">Firstname: </label><br/>'."\n";
                        $html .='<input type="text" name="userFName" id="userFName1" value="'.htmlentities(stripcslashes($_POST['userFName'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userFNameMsg'].'</div>'."\n";
                        $html .='<label for="userLName">Surname: </label><br/>'."\n";
                        $html .='<input type="text" name="userLName" id="userLName" value="'.htmlentities(stripcslashes($_POST['userLName'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userLNameMsg'].'</div>'."\n";
                        $html .='<label for="userEmail">Email: </label><br/>'."\n";
                        $html .='<input type="text" name="userEmail" id="userEmail" value="'.htmlentities(stripcslashes($_POST['userEmail'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userEmailMsg'].'</div>'."\n";
                        $html .='<label for="userPassword">Password: </label><br/>'."\n";
                        $html .='<input type="password" name="userPassword" id="userPassword1" value="'.htmlentities(stripcslashes($_POST['userPassword'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userPasswordMsg'].'</div>'."\n";
                        $html .='<label for="userPassword">Re-Enter Password: </label><br/>'."\n";
                        $html .='<input type="password" name="userPassword2" id="userPassword2" value="'.htmlentities(stripcslashes($_POST['userPassword2'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userPrematchPass'].'</div>'."\n";



                        $html .='<label for="userPhone">Telephone: </label><br/>'."\n";
                        $html .='<input type="text" name="userPhone" id="userPhone" value="'.htmlentities(stripcslashes($_POST['userPhone'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userPhoneMsg'].'</div>'."\n";
                        $html .='<label for="userAddress">Address: </label><br/>'."\n";
                        $html .='<input type="text" name="userAddress" id="userAddress" value="'.htmlentities(stripcslashes($_POST['userAddress'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userAddressMsg'].'</div>'."\n";
                        $html .='<label for="userCity">City: </label><br/>'."\n";
                        $html .='<input type="text" name="userCity" id="userCity" value="'.htmlentities(stripcslashes($_POST['userCity'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userCityMsg'].'</div>'."\n";
                        $html .='<label for="userCountry">NewZealand: </label><br/>'."\n";
                         $html .='<select name="Location">'."\n";
$html .='<option value=""></option>'."\n";
$html .='<option value="North-Island">North-Island</option>';
$html .='<option value="South-Island">South-Island</option>';
$html .='<option value="Other">Other</option>';
 $html .='<option value="Argentina" <?php if($_POST['YourCountry']=="Argentina") echo "selected=selected"; ?>>Argentina</option>';








                        $html .='<input type="text" name="userCountry" id="userCountry" value="'.htmlentities(stripcslashes($_POST['userCountry'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userCountryMsg'].'</div>'."\n";
                        $html .='<label for="userPostcode">Post Code: </label><br/>'."\n";
                        $html .='<input type="text" name="userPostcode" id="userPostcode" value="'.htmlentities(stripcslashes($_POST['userPostcode'])).'" /><br/>'."\n";
                        $html .='<div class="error">'.$vresult['userPostcodeMsg'].'</div>'."\n";
                        $html .='<input type="submit" name="register" value="Submit" id="submit"/>'."\n";
                    $html .='</fieldset>'."\n";
                $html .='</form>'."\n";
            $html .=' </div>'."\n";
        return $html;
    }
}

?>

</select>

<?php if($_POST['YourCountry']=="XXXXX") echo "selected=selected"; ?>

在其他选项标签中

更改

<select name="Location"> to  <select name="YourCountry">

**

action="'.$_SERVER['REQUEST_URI'].'"  is not good for Xss

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM