我是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时如何显示错误?对不起,如果我的问题不可理解,我真的不知道怎么说出我的问题。
答案 0 :(得分:1)
我发现了如何,我只需要在我的js中添加监听器iron-form-error。