【问题标题】:Polymer Iron-Form Output Error聚合物铁型输出误差
【发布时间】:2015-06-17 07:04:52
【问题描述】:

我是 Polymer 的新手,我正在使用 iron-form 组件向数据库提交一个。我的问题是我如何能够将错误报告回铁形式和 html?我尝试使用 php echo 并通过 json 数组返回它。但它没有显示在网页上。我该怎么做呢?这是我的代码:

include('config.php');
//Require the db file
include('db.php');
$db = new db($dbhost, $dbuser, $dbpassword, $dbmaster);
include('function.php');
$secure = new secure();

//Get the string.
$email = $secure->clean($_GET["email"]);
if ($secure->verify_email($email) == 'false') {
    echo '    <paper-dialog id="error">
    <h2>Error Registering Your Account</h2>
    <div>
      Invalid Email!
    </div>
</paper-dialog> ';
}

我为电子邮件输入了错误的输入:asdff,因此它会故意抛出错误,但是当我提交它时,当我查看网络选项卡时没有显示任何内容,我看到:

<paper-dialog id="error">
    <h2>Error Registering Your Account</h2>
    <div>
      Invalid Email!
    </div>
</paper-dialog> 

我的实际表单代码是:

<form is="iron-form" id="formPost" method="post" action="core/register.php">
      <paper-input char-counter error-message="Invalid input!" label="Username" maxlength="25" required name="username"></paper-input>
      <paper-input char-counter error-message="Invalid input!" label="Display Name" maxlength="35" required name="displayname"></paper-input>
      <paper-input char-counter error-message="Invalid input!" label="Password" maxlength="25" required type="password" name="password"></paper-input>
      <paper-input char-counter error-message="Invalid input!" label="Confrim Password" maxlength="25" required type="password" name="cfmpassword"></paper-input>
      <paper-input char-counter error-message="Invalid input!" label="Email" maxlength="25" required type="" name="email"></paper-input>
      <paper-checkbox required>By checking this box, you agree that you're atleast the age of 13 or above.</paper-checkbox>
      <br />

      <br>
      <div>

        <paper-button raised
          onclick="submitForm()"><iron-icon icon="check" style="margin-right:5px;"></iron-icon>Register</paper-button>
      </div>
</form>
<script type="text/javascript">
    function submitForm() {
        document.getElementById('formPost').submit();
    }
</script>

在使用 iron-ajax 时如何显示错误?抱歉,如果我的问题不是那么容易理解,我真的不知道如何表达我的问题。

【问题讨论】:

  • stackoverflow.com/questions/14220321/… 您可以使用答案中显示的回调吗?客户端 JS 等待服务器的响应,处理程序检查“onSuccess”、“onError”或 JS 承诺习语的响应属性。 github.com/youssef06/polymer-login-form/blob/master/login-form/… 检查底部的“onclick()” ....
  • @RobertRowntree 我会尝试看看其中哪一个有效,在 Polymer 网站上,他们有一些事件,例如 iron-form-error:Fired after the form is提交并收到错误。 iron-form-invalid:如果表单因为无效而无法提交时触发。 iron-form-response:在提交表单并收到响应后触发。 iron-form-submit:表单提交后触发。我是否也不需要在 JS 中使用这些事件之一?这是实际页面:link

标签: javascript php polymer


【解决方案1】:

我发现了方法,我只需要将监听器 iron-form-error 添加到我的 js 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-21
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    相关资源
    最近更新 更多