0

登録せずに一意のユーザー名を設定しようとしていますが、これは同じユーザー名を持つことになり、ユーザーが同じ名前を持つ可能性があるため、「このユーザーによるすべての投稿を表示」とは言えません。

基本的に、私はUser Submitted Postsと呼ばれるこの wordpress プラグインを使用しています。これは、ユーザーが登録なしで記事を投稿できるので優れていますが、名前が重複しているという問題があるため、解決策は入力フィールドがあることであると考えました。

<input name="user-submitted-name" type="text" value="" data-required="true" required placeholder="Your name" class="form-control input-lg usp-input">

そして、ランダムな一意の文字列を出力に追加して、次のようにします。

User 1: simon_xyz
User 2: simon_abc

PHPでランダムな文字列を生成するのは非常に簡単だと思います.PHPランダム文字列ジェネレーター

しかし、理想的には、「これはあなたのユーザー名です。コピーして、常にこれを使用してください」のようなことをユーザーに伝えたいと思います。登録がないため、電子メールの要件はありません。入力フィールドの値にランダムな一意の文字列を追加し、結果をライブで表示するにはどうすればよいですか?

このjQueryを使用して、チェックボックスの値をサイト上の他の何かの入力フィールドに追加しています:

            $('.checkTag').click(function() {
                $("#user-submitted-tags").val(
                    $('.checkTag:checked').map(function() {
                            return $(this).val();
                    }).get().join(', ')
                );
        });

おそらくそのようなものを使用できますが、ランダムな文字列は選択するものではないため、苦労しています。

ライブ結果は次のようになります。

<h2>This is your username</h2>
<h3>Use this user name the next time you write your post</h3>
<p>Your usernanme is: simon_xyz</p>
4

1 に答える 1

0

私が今理解している限り、あなたのコメントに基づいて、私は次のようなものを提案します:

ユーザー名入力ボックスを含むページ(<head><html>および を省略<body>)(質問のJSスニペットに基づいて、jQueryを使用できると想定しています):

$uniqueRandomString = ...;

?>

<form id="username-form"> (or get, that doesn't really matter, just remember to adjust it on the processing page.)
    <input type="text" name="username" id="username-input" /> <? echo "+ " . $uniqueRandomString; ?>
    <input type="hidden" name="unique-random-string" value="<? echo $uniqueRandomString; ?>"/>
    <input type="submit" />
</form>
<script>
    $("#username-form").on('submit', function() { // Of course you could change the ID of the form, but you'll have to change this as well in that case.
        $.get('url/of/processing/page.php?' + $(this).serialize(), function(data) {
            if (data.indexOf("SUCCESS") == 0) {
                username = data.substring(8);
                $('body').append("<h2>This is your username</h2>
                                  <h3>Use this user name the next time you write your post</h3>
                                  <p>Your usernanme is: " + username + "</p>");
            } else {
                // Display an error message.
            }
        });
    });

ユーザー名を処理するページ:

<?
// Check if the unique random string - now contained is $_POST['unique-random-string'] - is valid!
// If not, make the expression in this if-statement evaluate to true.
if ($error) echo "ERROR";
else echo "SUCCESS:" . $_GET['username'];
?>
于 2013-09-15T16:18:12.803 に答える