我是Php的新手,我很难设置下面的表格。当我按发送时,表格不会被发送。我希望用户在同一页面上发送。这就是为什么我使用$ _SERVER [" PHP_SELF"]但显然有些事情并没有正常工作。你能救我一下吗?
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"];?>" id="form_body_container">
<div class="form_icon_container"><img src='img/icon/fun_1200.png' class='icon_form iconq'></div>
<div class='box_form'>
<div class="box_form_inside">
<p class='form_question_title'>Q1 What do you do for fun?</p>
<input class="form_radios" type="radio" name="Q1" value="Play games"><p class='form_options'>Play games</p><br class="br_form">
<input class="form_radios" type="radio" name="Q1" value="Exercise"><p class='form_options'>Exercise</p><br class="br_form">
<input class="form_radios" type="radio" name="Q1" value="Go out"><p class='form_options'>Go out</p><br class="br_form">
<input class="form_radios" type="radio" name="Q1" value="Party"><p class='form_options'>Party</p>
</div>
</div>
<div class="form_icon_container"><img src='img/icon/food_1200.png' class='icon_form iconq'></div>
<div class='box_form'>
<div class="box_form_inside">
<p class='form_question_title'> Q2 Which food do you like?</p>
<input class="form_radios" type="radio" name="Q2" value="Lorem"><p class='form_options'>Starters</p><br class="br_form">
<input class="form_radios" type="radio" name="Q2" value="Lor"><p class='form_options'>Main courses</p><br class="br_form">
<input class="form_radios" type="radio" name="Q2" value="L"><p class='form_options'>Deserts</p><br class="br_form">
<input class="form_radios" type="radio" name="Q2" value="Lore"><p class='form_options'>Snacks</p>
</div>
</div>
<div class="form_icon_container"><img src='img/icon/genie_1200.png' class='icon_form iconq'></div>
<div class='box_form'>
<div class="box_form_inside">
<p class='form_question_title'>Q3 What do you wish?</p>
<input class="form_radios" type="radio" name="Q3" value="Lorem"><p class='form_options'>Money</p><br class="br_form">
<input class="form_radios" type="radio" name="Q3" value="Lor"><p class='form_options'>Become very smart</p><br class="br_form">
<input class="form_radios" type="radio" name="Q3" value="L"><p class='form_options'>Become immortal</p><br class="br_form">
<input class="form_radios" type="radio" name="Q3" value="Lore"><p class='form_options'>Possess super powers</p>
</div>
</div>
<div class="form_icon_container"><img src='img/icon/love_1200.png' class='icon_form iconq'></div>
<div class='box_form'>
<div class="box_form_inside">
<p class='form_question_title'>Q4 Your ideal relationship?</p>
<input class="form_radios" type="radio" name="Q4" value="Lorem"><p class='form_options'>Short but eventful</p><br class="br_form">
<input class="form_radios" type="radio" name="Q4" value="Lor"><p class='form_options'>Long but uneventful</p><br class="br_form">
<input class="form_radios" type="radio" name="Q4" value="L"><p class='form_options'>Not serious</p><br class="br_form">
<input class="form_radios" type="radio" name="Q4" value="Lore"><p class='form_options'>Being single</p>
</div>
</div>
<div class="form_icon_container"><img src='img/icon/work_1200.png' class='icon_form iconq'></div>
<div class='box_form'>
<div class="box_form_inside">
<p class='form_question_title'>Q5 Your ideal work situation?</p>
<input class="form_radios" type="radio" name="Q5" value="Lorem"><p class='form_options'>Making a lot of money</p><br class="br_form">
<input class="form_radios" type="radio" name="Q5" value="Lor"><p class='form_options'>Doing something you like</p><br class="br_form">
<input class="form_radios" type="radio" name="Q5" value="L"><p class='form_options'>Peaceful workplace</p><br class="br_form">
<input class="form_radios" type="radio" name="Q5" value="Lore"><p class='form_options'>Improving your skills</p>
</div>
</div>
<div class="form_icon_container"><img src='img/icon/language_1200.png' class='icon_form iconq'></div>
<div class='box_form'>
<div class="box_form_inside">
<p class='form_question_title'>Q6 What is your mother tongue?</p>
<input class="form_radios" type="radio" name="Q6" value="Lorem"><p class='form_options'>English</p><br class="br_form">
<input class="form_radios" type="radio" name="Q6" value="Lor"><p class='form_options'>French</p><br class="br_form">
<input class="form_radios" type="radio" name="Q6" value="L"><p class='form_options'>Chinese</p><br class="br_form">
<input class="form_radios" type="radio" name="Q6" value="Lore"><p class='form_options'>Other</p>
</div>
</div>
<div class="form_icon_container"><img src='img/icon/world_1200.png' class='icon_form iconq'></div>
<div class='box_form'>
<div class="box_form_inside">
<p class='form_question_title'>Q7 Where do you come from?</p>
<input class="form_radios" type="radio" name="Q7" value="Lorem"><p class='form_options'>USA</p><br class="br_form">
<input class="form_radios" type="radio" name="Q7" value="Lor"><p class='form_options'>UK</p><br class="br_form">
<input class="form_radios" type="radio" name="Q7" value="L"><p class='form_options'>France</p><br class="br_form">
<input class="form_radios" type="radio" name="Q7" value="Lore"><p class='form_options'>Other</p>
</div>
</div>
<button type="button" name="submit" value="Submit" id='button_form'>Submit</button>
<div class='clear'></div>
</form>
答案 0 :(得分:0)
您必须使用“提交”类型按钮而不是实际按钮。
您的错误
您有一个普通按钮<button type="button" name="submit" value="Submit" id='button_form'>Submit</button>
更正
您必须拥有“提交”类型按钮,例如<input type="submit" value="Submit" id="button_form" />
或<button type="submit" name="submit" value="Submit" id='button_form'>Submit</button>
(请注意type =“submit”)
此外,在HTML 5中,不再需要表单中的“action”属性,它将在同一页面上发送表单:)!
答案 1 :(得分:0)
$ _ SERVER [“PHP_SELF”]
返回相对于根目录的路径尝试将$ _SERVER [“PHP_SELF”]与根路径连接。
如果您不确定缺少哪个部分,只需在网页顶部回显$ _SERVER [“PHP_SELF”],看看实际路径的哪一部分缺失!