从表单链接到URL的最简单方法是什么?
表单示例:
<form class="form-horizontal" role="form" action="chat" method="post">
<fieldset>
<!-- Text input-->
<div class="form-group">
<label class="col-sm-2 control-label" for="nickname">Nickname</label>
<div class="col-sm-10">
<input id="nickname" name="nickname" type="text" placeholder="Nickname" class="form-control" required="required">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-sm-2 control-label" for="age">Age</label>
<div class="col-sm-10">
<select id="age" name="age" class="form-control">
<option value=""></option>
<?php
for($value = 18; $value <= 100; $value++){
echo('<option value="' . $value . '">' . $value . '</option>');
}
?>
</select>
</div>
</div>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-sm-2 control-label" for="gender">Gender</label>
<div class="col-sm-10">
<label class="radio" for="gender-0">
<input type="radio" name="gender" id="gender-0" value="Female" required="required">
Female
</label>
<label class="radio" for="gender-1">
<input type="radio" name="gender" id="gender-1" value="Male" required="required">
Male
</label>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-sm-2 control-label" for="location">Location</label>
<div class="col-sm-10">
<select id="location" name="location" class="form-control">
<option value=""></option>
<option value="Canada">Canada</option>
<option value="France">France</option>
<option value="Germany">Germany</option>
<option value="Italy">Italy</option>
<option value="Mexico">Mexico</option>
<option value="Russia">Russia</option>
<option value="Spain">Spain</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States">United States</option>
</select>
</div>
</div>
<!-- Multiple Checkboxes (inline) -->
<div class="form-group">
<label class="col-sm-2 control-label" for="checkbox"></label>
<div class="col-sm-10">
<label class="checkbox inline" for="checkbox-0">
<input type="checkbox" name="checkbox" id="checkbox-0" value="I agree to the Terms of Use" required="required">
I agree to the <a href="legal.php">Terms of Use</a>
</label>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-sm-2 control-label" for="button"></label>
<div class="col-sm-offset-2 col-sm-10">
<button id="button" name="button" class="btn btn-lg btn-success" type="submit">Enter Chat</button>
</div>
</div>
</fieldset>
</form>
那么,如何才能创建一个URL,例如:
start.php?nickname=Steve&age=18&gender=male&location=United%23Kingdom
谢谢
史蒂夫
发布于 2014-03-11 14:29:36
您可以使用进行此操作,也可以将所有$_POST参数连接起来,然后重定向。
发布于 2014-03-11 14:43:31
将表单方法更改为get
,方法为<form method="get">
每个表单字段及其值将以&field=value
的形式追加到URL
GET
和POST
是两种不同的数据发送方法。但是要小心,只有在没有发送安全信息的情况下才应该使用GET
。数据,如密码,信用卡号码,帐号,和其他机密的东西只能用POST
发送。为什么?仅仅因为这些数据显示在URL
中。POST
是另一种方法。服务器处理POST请求,并将所有字段及其相应的值存储在某个地方,以便您可以在表单提交的页面上访问它们。
发布于 2014-03-11 14:55:14
将第一行更改为:
<form class="form-horizontal" role="form" action="start.php" method="get">
action
中,键入要将表单发布到的页面的路径和名称。在您的示例中,这是start.php
。method
中,如果要将表单值发送到url中,则键入get
。https://stackoverflow.com/questions/22328716
复制相似问题