Ik heb een contactform waar dit script onder draait.
Nu heb ik hier twee problemen mee. De eerste is dat ik graag de output anders wil, als volgt:
Ik zou de output graag als volgt willen hebben:
Het tweede probleem is, dat het script ervoor zorgt dat elke keer als errors in de validatie zijn, dat het script een nieuwe regel toevoegt met de error melding. Dit moet natuurlijk maar één keer.
Wie kan mij hiermee helpen?
Code:
// Contact form
$(document).ready(function() {
$('form#contactform').submit(function() {
$('form#contactform .error').remove();
var hasError = false;
$('.requiredField').each(function() {
if(jQuery.trim($(this).val()) == '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('<span class="error_text">You forgot to enter your '+labelText+'.</span>');
hasError = true;
} else if($(this).hasClass('email')) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test(jQuery.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('<span class="error_text">You entered an invalid '+labelText+'.</span>');
hasError = true;
}
}
});
if(!hasError) {
$('form#contactform li.buttons button').fadeOut('normal', function() {
$(this).parent().append('<img src="/wp-content/themes/td-v3/images/template/loading.gif" alt="Loading…" height="31" width="31" />');
});
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data){
$('form#contactform').slideUp("fast", function() {
$(this).before('<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent. I check my email all the time, so I should be in touch soon.</p>');
});
});
}
return false;
});
});
Nu heb ik hier twee problemen mee. De eerste is dat ik graag de output anders wil, als volgt:
PHP:
<li><label for="contactName"><?php _e('Name', 'cc_language'); ?> *</label>
<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" />
<span class="error_text"><?php echo $nameError; ?></span>
</li>
Ik zou de output graag als volgt willen hebben:
PHP:
<li><label for="contactName"><?php _e('Name', 'cc_language'); ?> *</label>
<span class="error_sub">
<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" />
<span class="error_text"><?php echo $nameError; ?></span></span>
</li>
Het tweede probleem is, dat het script ervoor zorgt dat elke keer als errors in de validatie zijn, dat het script een nieuwe regel toevoegt met de error melding. Dit moet natuurlijk maar één keer.
Wie kan mij hiermee helpen?