使用urlencode和GET以PHP格式保存用户值

时间:2017-12-07 06:42:12

标签: php forms urlencode

构建用于搜索的PHP表单。当用户提交表单时,表单输入字段将转换为urlencoded值。

问题 - 当用户输入 - mango cherry进入搜索字段和表单时,搜索字段将更改为mango+cherry

HTML表单

<form action = <?php url_echo('/task/task.php') ?>  method ='get'>
<div class='row' >
    <div class="form-group">
        <label for="clientname">Client Name</label>
        <input type="text" id="clientname" name="clientname" value="<?php echo h_url( h($_GET['clientname']) ); ?>">
    </div>    
</div>
<div class="row">
    <input type="submit" class="btn btn-primary" value="Search" >
</div>
</form>

PHP

function h($str_to_encode) {
    return htmlspecialchars ($str_to_encode);
}
function h_url($str_to_encode) {
    return urlencode($str_to_encode);
}

使用GET,因为我希望URL包含搜索参数。这是一个简化的形式,我有更多的领域。我正在学习PHP,并且要遵循最佳实践。我愿意改变表单提交的整个方法。

0 个答案:

没有答案