0

機能を変更できるサイドバーのあるページがあります。それぞれの異なるサイドバー レイアウトは div です。サイドバーの 2 つはテキスト入力を可能にします。現在、すべてのサイドバー レイアウトを処理するハンドラーを呼び出す app.get ステートメントが 1 つありますが、このソリューションは非常に面倒です。さまざまなサイドバーを分割して、さまざまなハンドラー関数を操作するにはどうすればよいですか?

たとえば、app.js に次のステートメントがあります。

app.post('/', home.sidebarHandler);

sidebarHandler は現在、ログインと新規ユーザーとしての登録の両方を処理していますが、これを 2 つの別個の関数で実行したいと考えています。

これが私の翡翠コードの一部です。これはdivの1つです:

form#sbCreateBox(method='post')
    input.sbText(type='text', name= 'usernameReg', placeholder='Username', required)
    input.sbText(type='text', name= 'acctHolderName', placeholder='Name')
    input.sbText(type='email', name= 'useremail', placeholder='Email Address',      required)
    input.sbText(type='password', name= 'passwordReg', autocomplete='off',    placeholder='Password', required)
    input.sbText(type='password', name= 'passConfirm', autocomplete='off', placeholder='Confirm Password', required)
    input#sbCreateButton(type='submit', value='Create Account')

個別の app.post ステートメントを持つようにルートを設定するにはどうすればよいですか?

4

1 に答える 1

0

サーバー側のコードで 2 つのルートを定義できます。

app.post('/register', home.registerUser);
app.post('/login', home.loginUser);

そして、HTML を更新して、ユーザーのアクションに応じて正しい URL (/register または /login) に投稿します。

編集 2 つのフォームを作成できます。1 つは /register に投稿し、もう 1 つは /login に投稿します (フォーム要素の action 属性に注意してください)。

登録フォーム

form#sbCreateBox(method='post' action='/register')
    input.sbText(type='text', name= 'usernameReg', placeholder='Username', required)
    input.sbText(type='text', name= 'acctHolderName', placeholder='Name')
    input.sbText(type='email', name= 'useremail', placeholder='Email Address',      required)
    input.sbText(type='password', name= 'passwordReg', autocomplete='off',    placeholder='Password', required)
    input.sbText(type='password', name= 'passConfirm', autocomplete='off', placeholder='Confirm Password', required)
    input#sbCreateButton(type='submit', value='Create Account')

ログインフォーム

form#sbCreateBox(method='post' action='/login')
    input.sbText(type='text', name= 'usernameReg', placeholder='Username', required)
    input.sbText(type='password', name= 'passwordReg', autocomplete='off',    placeholder='Password', required)
    input#sbCreateButton(type='submit', value='Login')
于 2012-12-20T19:19:43.430 に答える