1

URLで渡された文字列に応じて、ページにテキストボックスを自動入力することは可能ですか?例えば:

次のフォームがあるとします。

<form name="form_reservation" id="form-reservation">
                    <div style="padding:10px 20px 10px 10px;">
                    <label for="reservation-id">Reservation ID</label>
                        <input name="reservation_id" id="reservation-id" class="reservationid" style="width:120px !important"/>
                        <div style="padding:5px 20px 0px 10px;" class="res_message" id="res-message">&nbsp;</div>
                        <input type="submit" class="button" value="Search Reservation" name="search_button" style="width:150px !important; margin:10px 0px 0px 5px;"/>
                        <input type="button" class="button" value="Clear" style="width:150px !important; margin:10px 0px 0px 5px;" onclick="resetForms('reservation')" />
                    </div>
                </form>

そして、ユーザーはリンクが記載された電子メールを受信しました:www.website.com/formpage.html ######

ここで、######は、フォームのreservation-idフィールドに入力したいIDです。これを実現する方法はありますか?

4

2 に答える 2

1

ユーザーがクリックしたURLがのように見えると仮定すると、www.website.com/formpage.html?id=12345GETを使用して入力「値」フィールドにそれを吐き出すことができます。例:

<input value="<?php echo htmlspecialchars($_GET["id"]); ?>" name="reservation_id" id="reservation-id" class="reservationid" style="width:120px !important" />

これは、phpでそれを行う方法です。

編集:

@Esailijaのコメントによると、私はそれをhtmlspecialchars関数でラップしました。これは、私が理解している限り、XSS攻撃からの保護に役立ちます。

于 2012-04-27T13:36:35.437 に答える
0

Javascript:

<script>
    var hash = window.location.hash.replace('#', ''); // get hash and replace the '#' (hash) tag
    document.getElementById('reservation-id').value = hash; // add value to input
</script>

私はあなたがハッシュの場所について話していると仮定しましたurl.html#1111、これはJavaScriptでのみ達成することができます。

于 2012-04-27T13:39:24.620 に答える