Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Last active November 3, 2023 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafauysal/b84ced33737a399bda4bb742113bc851 to your computer and use it in GitHub Desktop.
Save mustafauysal/b84ced33737a399bda4bb742113bc851 to your computer and use it in GitHub Desktop.
<?php
add_action( 'wp_footer', 'magic_login_auto_fill_email_from_url' );
add_action( 'login_footer', 'magic_login_auto_fill_email_from_url' );
function magic_login_auto_fill_email_from_url() {
?>
<script>
// Function to get URL parameters
function getURLParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
// Get the email parameter from the URL
const email = getURLParameter('email');
// If the email parameter exists, populate the input field named "log"
if (email) {
const logInput = document.querySelector('input[name="log"]');
if (logInput) {
logInput.value = email;
}
}
</script>
<?php
}
@mustafauysal
Copy link
Author

 <script>
		// Function to get URL parameters
		function getURLParameter(name) {
			const urlParams = new URLSearchParams(window.location.search);
			return urlParams.get(name);
		}

		// Get the email parameter from the URL
		const email = getURLParameter('email');

		// If the email parameter exists, populate the input field named "log"
		if (email) {
			const logInput = document.querySelector('input[name="log"]');
			if (logInput) {
				logInput.value = email;

				// Find the form containing the input field
				const form = logInput.closest('form');

				// If the form exists, submit it
				if (form) {
					form.submit();
				}
			}
		}
    </script>

for auto form submit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment