Dears,
I have a user form with activation field (check box) and date expiration fields,
when the user is activated the expiration date should be calculated using JS and inserted in the user profile. it was working fine I don't know what is wrong now. the expiration date in not inserted in the user profile, the field is empty.
Below is the form and JS.
------------------------------Form----------------------------------------------------
[creduserform]
[cred_field field='form_messages' class='alert alert-warning']
<div class="form-group" hidden>
[cred_field field="user_email" class="form-control" output="bootstrap"]
</div>
<div class="form-group" hidden>
[cred_field field="expiration-date" force_type="field" class="form-control" output="bootstrap"]
</div>
<div class="form-group" >
[cred_field field="user-account-status" force_type="field" class="form-control" output="bootstrap"]
</div>
<br>
[cred_show_group if="( $(user-account-status) eq '1' )" mode="none"]
<div class="form-group">
<label>[cred_i18n name='user-account-details-label']Account Details[/cred_i18n]</label>
[cred_field field="user-account-details" force_type="field" class="form-control" output="bootstrap"]
</div>[/cred_show_group]
<center>[cred_field field='form_submit' output='bootstrap' value='Activate' class='btn btn-primary btn-lg']</center>
[/creduserform]
-----------------------JS--------------------------------
var day2 = new Date();
day2.setFullYear(day2.getFullYear()+1);
var dd = day2.getDate();
var mm = day2.getMonth()+1;
var yyyy = day2.getFullYear();
if(dd<10)
{
dd='0'+dd;
}
if(mm<10)
{
mm='0'+mm;
}
day2 = mm+'/'+dd+'/'+yyyy;
document.querySelector('input[name="wpcf-expiration-date"]').value = day2;
Hello and thank you for contacting the Toolset support.
The code seems ok to me. Would you allow me temporary access to your website to check this further? Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Please note that I'll need FTP access too.
Let me know what form and where it is being used on the frontend.
In fact, the Javascript code is not handling the case of multiple forms, it will update the first date field that encounters on the page. Try the following code instead:
jQuery(function($){
// 1st part: calculating the date.
var day2 = new Date();
day2.setFullYear(day2.getFullYear()+1);
var dd = day2.getDate();
var mm = day2.getMonth()+1;
var yyyy = day2.getFullYear();
if(dd<10)
{
dd='0'+dd;
}
if(mm<10)
{
mm='0'+mm;
}
day2 = mm+'/'+dd+'/'+yyyy;
// 2nd part: updating all the date fields inside all the user forms of the page
$('form.cred-user-form').each(function(){
var form = jQuery(this)
form.find(''input[name="wpcf-expiration-date"]').val(day2);
})
})
Yes it is working now.
My issue is resolved. Thank you!