user3339454
user3339454

Reputation: 117

Polymer Iron-Form Output Error

I'm new to Polymer, and I'm using the iron-form component to submit a to the database. My question is how would I be able to report an error back out to iron-form and to the html? I have tried using php echo and return it through a json array. but it did not show on the webpage. How would I go about doing this? here is my code:

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> ';
}

I have put in a wrong input for the email which is: asdff, so that it would purposely throw an error, but when I submit it, nothing shows when I look in the network tab, I see:

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

My code for the actual form is:

<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>

How would I go about showing the errors when using iron-ajax? Sorry if my question isn't that understandable I really didn't know how to word my question.

Upvotes: 1

Views: 713

Answers (1)

user3339454
user3339454

Reputation: 117

I found out how, I just had to add the listener iron-form-error into my js.

Upvotes: 1

Related Questions