0

私のアプリケーションでは、node.js(https://github.com/caolan/forms)のフォームモジュールを使用しています。スタートアップページにフォームを表示しているときにjadeファイルでエラーが発生します。誰かがこの問題を修正するのを手伝ってもらえますか?

app.js

  var http = require('http'),
  express = require('express'),
  app = express();

  var fields = forms.fields,
  validators = forms.validators,
  widgets = forms.widgets;

  var reg_form = forms.create({
  username: fields.string({required: true}),
  password: fields.password({required: true}),
  confirm: fields.password({
    required: true,
    validators: [validators.matchField('password')]
}),
email: fields.email()
  });

app.configure(function () {
  app.set('views', __dirname);
  app.set('view engine', 'jade');

  app.use(express.bodyParser());
  app.use(app.router);


  });

  app.get('/', function (req, res) {
     res.render('page', {
     locals: {
         title: 'Filling out the form...',
         form: reg_form.toHTML()
     }
  });
   });

 app.post('/', function (req, res) {
 reg_form.handle(req, {
    success: function (form) {
        res.render('page', {
            locals: {
                title: 'Success!'
            }
        });
    },
    other: function (form) {
        res.render('page', {
            locals: {
                title: 'Failed!',
                form: form.toHTML()
            }
        });
    }
});
});

page.jade

 h1= title

-  if (typeof form !== 'undefined')
form(method='post')
  != form
  input(type='submit')

page.jsont

      <html>
      <head>
      <title>Example Form</title>
      <style>
        form {
            border-top: 1px dashed #ccc;
            width: 375px;
        }
        label {
            position: relative;
            width: 200px;
            top: 6px;
        }
        .required label {
            font-weight: bold;
        }
        .field {
            border-bottom: 1px dashed #ccc;
            padding: 10px 5px 15px 5px;
            position: relative;
        }
        .field input, .field select, .field textarea {
            margin: -20px 0 0 175px;
            width: 180px;
        }
        .field textarea {
            margin-top: -15px;
        }
        .field input[type='checkbox'] {
            position: relative;
            margin-left: 32px;
            top: 4px;
        }
        .field fieldset input {
            margin: 0;
            width: 20px;
        }
        .error {
            background: #ffcccc;
        }
        .error_msg {
            color: red;
            margin: -15px 0 0 0;
            padding: 5px 0;
        }
        input[type='submit'] {
            margin-top: 20px;
        }
    </style>
   </head>
    <body>
    <h1>Example Form</h1>
    <form action="" method="GET">
        {form}
        <input type="submit" />
    </form>
 </body>
 </html>

ページのエラー

  ReferenceError: /home/manigandan/workspace/CreatingForm/page.jade:1
    > 1| h1= title
      2| 
      3|   - if (typeof form !== 'undefined')
      4|     form(method='post')

title is not defined
at eval at <anonymous>   (/home/manigandan/workspace/CreatingForm/node_modules/jade/lib/jade.js:176:8)
at /home/manigandan/workspace/CreatingForm/node_modules/jade/lib/jade.js:181:12
at Object.render (/home/manigandan/workspace/CreatingForm/node_modules/jade/lib/jade.js:216:14)
at View.engine (/home/manigandan/workspace/CreatingForm/node_modules/jade/lib/jade.js:243:13)
at View.render (/home/manigandan/workspace/CreatingForm/node_modules/express/lib/view.js:75:8)
at Function.render (/home/manigandan/workspace/CreatingForm/node_modules/express/lib/application.js:504:10)
at ServerResponse.render (/home/manigandan/workspace/CreatingForm/node_modules/express/lib/response.js:753:7)
at /home/manigandan/workspace/CreatingForm/app.js:34:9
at callbacks (/home/manigandan/workspace/CreatingForm/node_modules/express/lib/router/index.js:161:37)
at param (/home/manigandan/workspace/CreatingForm/node_modules/express/lib/router/index.js:135:11)
4

1 に答える 1

0

これは、とは関係ありませんformsが、パラメータをに渡す方法とは関係ありませんrender

app.get('/', function (req, res) {
  res.render('page', {
    title: 'Filling out the form...',
    form: reg_form.toHTML()
  });
});

余分なものがどのようにlocals削除されるかに注意してください。

于 2013-03-26T07:39:03.600 に答える