1
Hello!
There’s a form I needed to put in the name as dynamic. Originally, this name was just registerformpopup
. Now I put as registerformpopup
+ the title of the page that varies according to the page on which the user completed the form.
That worked perfectly.
<form class="<?php if ( get_theme_mod( 'thim_auto_login', true ) ) {
echo 'auto_login';
}
?>" name="<?php echo 'registerformpopup' . get_the_title() ?>"
action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>"
method="post" novalidate="novalidate">
<?php wp_nonce_field( 'ajax_register_nonce', 'register_security' ); ?>
The problem is that I realized that there were various functions in javascript
who wore the same name to have them executed.
What I thought was to also make it dynamic. However I’m not able to do the functions in JS
work.
The original function in JS
is the following:
register_ajax: function() {
$('#thim-popup-login form[name=registerformpopup]').on('submit', function(e) {
e.preventDefault();
if (!thim_eduma.validate_form($(this))) {
return false;
}
Tentei de várias formas mas não consegui. Tentei colocar um código php dentro do JS mas não deu. Também tentei o seguinte:
register_ajax: function() {
$('#thim-popup-login form[name="registerformpopup' + document.title + '"]').on('submit', function(e) {
e.preventDefault();
if (!thim_eduma.validate_form($(this))) {
return false;
}
Can someone help me?
You have a syntax error in
$('#thim-popup-login form['name=registerformpopup ' + document.title]')
... this concatenation could be$('#thim-popup-login form[name="registerformpopup' + document.title + '"]')
– Sergio
Hi Sergio, all right? In fact the concatenation was wrong. Thank you! But it still didn’t work. :(
– Carlos Guimarães
Dude, you don’t need to take the name of the form to use it. There are mts ways to catch it without necessarily using the name.
– Sam
For example:
$("form").on("submit", function(){ $(this) });
...the$(this)
is the form that has been submitted, no matter what is in it.– Sam
In the same php code there is the login and registration form. I believe this is the reason to use the name.
– Carlos Guimarães