1

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.

user3339454
  • 117
  • 9
  • http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call can you make use of the callbacks shown in the answer? client-side JS waits on server's response and a handler checks the response properties for "onSuccess", "onError" or the JS promise idiom. https://github.com/youssef06/polymer-login-form/blob/master/login-form/js/login-form.js check the "onclick()" at bottom .... – Robert Rowntree Jun 17 '15 at 14:45
  • @RobertRowntree I'll try to see which one of those work and on the Polymer website, they have some Events like **iron-form-error**:Fired after the form is submitted and an error is received. **iron-form-invalid**:Fired if the form cannot be submitted because it's invalid. **iron-form-response**: Fired after the form is submitted and a response is received. **iron-form-submit**:Fired after the form is submitted. Wouldn't I need to use one of these events in the JS as well? Here is the actual page: [link](https://elements.polymer-project.org/elements/iron-form) – user3339454 Jun 17 '15 at 19:59

1 Answers1

1

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

user3339454
  • 117
  • 9