2016-12-07 125 views
0

我为我们组织的比赛做了注册表。 在这种形式下,你必须选择从索引窗口竞争登录。链接到固定值的PHP表单?

是否有可能使在HTML(使用<a href>)一些链接重定向到报名表与已选定的比赛(一些固定值) ?

+2

请您分享我们如何实现窗体? – Alexandre

回答

0

您可以使用GET参数。

<a href='www.example.com/?CompName=competitionName'>Competition Name</a> 

<?php 
    if(isset($_GET['CompName'])){ 
     $sCompetitionName = $_GET['CompName']; 
    } 
?> 

然后,当您创建选项列表时,检查名称是否与列表名称匹配。如果它选择它。

0

是的,你可以,你可以使用$ _GET参数来做到这一点。首先在您的比赛列表页面上添加一个链接到您的表格页面。

<a href="url-to-competition-page?competition=your-value-here">Register for YOUR COMPETITION NAME HERE</a> 

然后在您的比赛注册表中查找获取参数。在下面的例子中,我将使用一个html选择框。

$competitions = [ 
    'competition-value' => 'Competition name', 
    'competition-value-2' => 'Competition name 2', 
]; 

// Look for your get param, if it is not found set a default. In this case an empty string 
$selectedCompetition = (isset($_GET['competition'])) ? $_GET['competition'] : ''; 

从您的比赛名单中生成选择。该列表仅用于演示:)

<select name="competition"> 
<?php foreach($competitions as $key => $value):?> 
     <option value="<?php echo $key;?>" <?php echo ($selectedCompetition == $value) ? 'selected' : '';?>><?php echo $value;?></option> 
<?php endforeach;?> 
</select>