Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>METHOD 1</strong><br> If you would like to have an error message per validated field then:<br><br> You have a form input, for example:</p> <pre><code>&lt;input name="myfield" id="myfield" type="text"&gt; </code></pre> <p>Next to it, you can add a div or span with your alert/error message and appropriate id, something like:</p> <pre><code>&lt;input name="myfield" id="myfield" type="text"&gt; &lt;span id="myfield_Error" class="none"&gt;Please fill this field&lt;/span&gt; </code></pre> <p>Where class="none" in your css, is used to hide the error container. Something like: </p> <pre><code>.none {display:none;} </code></pre> <p>Now for your jquery part:</p> <pre><code>var myfield= $("#myfield").val(); if (myfield=='') { $("#myfield_error").show(); } </code></pre> <p>The trick here is to named your error containers in a similar way as your target form element you validate. So for id="fieldA" you will have the error id="fieldA_error". <br><br></p> <p><strong>EDIT1</strong>:<br> If you need to use classes, you need to modify a little the code.<br> You need to form an array of element to check.<br> Loop through the array.<br> And use somethign like:<br></p> <pre><code>var fieldName = $(this).attr('name'); var fieldVallue = $(this).val(); if (fieldVallue=='') { $("#"+fieldName+"_error").show(); } else { $("#"+fieldName+"_error").hide; } </code></pre> <p><strong>Method 2</strong><br><br> If you just like to have 2 different containers, one for success and one for error/failed validation, then you need to output something different from your php file.<br> So your php file can output someting like:<br></p> <pre><code>$report['status'] = 'error' $report['message'] = 'error in xxxx field - please use a proper email' echo json_encode($report); </code></pre> <p>Then in your ajax success you can check what response you got. You parse your json response and based on your 'status', you put your 'message' in different containers<br> <br> I hope this is what you look for.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload