User registration getting duplicated

I have a user registration system copied from various examples on the forum (thanks :slight_smile: ). However I have a problem in that it often runs multiple times and I end up with multiple copies of the same user being registered.

I know I can add a step to check if the registration is already been performed, and I will do this as I want to let the user know that their email or user name is already in use. However, if I return an alert to the user to tell them their user name is already in use, then this check should not really trigger for duplicates or we will regularly be telling users they have already registered when the real problem is just that the script has run twice.

I’m also not completely sure if this would work 100% of the time as I’m not sure if scripts will run atomically or if they can be interrupted in multiple threads.

Below is my server connect script - it sends an email to the user and they need to click on the link to complete registration. This normally results in multiple entries in the user database, and multiple emails.

How do others handle this situation?

When does it run multiple times? Is the user clicking the submit button multiple times?
Is this server action attached to a form, maybe you have it included on the page or something is not right with the success event on the page etc.

Can you post your page source between the <body> tags, wrapped in three backticks ``` here ?

No - just once as far as I can tell.

<body is="dmx-app" id="opensmarthouse">
	<div class="modal fade" id="privacy" is="dmx-bs4-modal" tabindex="-1" role="dialog">
		<div class="modal-dialog modal-lg modal-dialog-scrollable modal-dialog-centered" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h5 class="modal-title">Privacy Policy</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
					<?php include '../privacypolicy.html'; ?>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
				</div>
			</div>
		</div>
	</div>
	<?php include '../navbar.php'; ?>

	<div class="container">
		<div class="row row-cols-md-7 justify-content-md-center mt-md-5 ml-md-auto mr-md-auto">
			<div class="border rounded rounded-sm col-md-6 col-sm-8 col-10 col-xl-4 col-lg-6 border-info mt-md-0 ml-md-auto mr-md-auto mb-5">
				<div class="d-block">
					<h3 class="text-dark text-md-center mb-md-4">Register</h3>
					<form id="login" method="post" is="dmx-serverconnect-form" action="../dmxConnect/api/user/register.php" dmx-on:success="browser.goto('../index.php')">

						<div class="form-row mb-sm-2">
							<div class="col">
								<input id="firstname" name="firstname" type="text" class="form-control" placeholder="First Name...">
							</div>
							<div class="col">
								<input id="lastname" name="lastname" type="text" class="form-control" placeholder="Last Name...">
							</div>
						</div>

						<input id="username" name="username" type="text" class="form-control mb-md-4 mb-2" placeholder="Enter Username..." autocomplete="off" autofocus tabindex="1" required="" data-rule-alphanumeric="" minlength="5" maxlength="30">
						<input id="email" name="email" type="email" class="form-control mb-2" placeholder="Enter Email Address..." required="" data-rule-email="" tabindex="2" maxlength="75">
						<input id="password" name="password" type="password" class="form-control mb-md-4 mb-2" placeholder="Enter Password..." tabindex="3" autocomplete="off" data-msg-pattern="" data-msg-minlength="" data-rule-equalto="{{password}}"
							data-msg-maxlength="" data-msg-required="">
						<input id="password1" name="password1" type="password" class="form-control mb-md-4 mb-2 mb-sm-2" placeholder="Enter Password..." tabindex="3" autocomplete="off" data-msg-pattern="" data-msg-minlength=""
							data-rule-equalto="{{password}}" data-msg-maxlength="" data-msg-required="">

						<div class="form-row mb-sm-2 ml-sm-1 mr-sm-1">
							<div class="form-check">
								<input class="form-check-input" type="checkbox" value="" id="input1" name="input1">
								<label class="form-check-label" for="input1">Accept our <a dmx-on:click="privacy.show()" class="badge badge-info">privacy policy</a></label>
							</div>
						</div>
						<div class="form-row mb-4 ml-sm-1 mr-sm-1">
							<div id="captcha1" class="g-recaptcha" data-sitekey="6LeneNsUAAAAAKv5Qb09vaqtIOnqKvP1yBLXSSin"></div>
						</div>

						<div class="alert" id="alert1" is="dmx-bs4-alert" role="alert">
							<p>alert!</p>
						</div>
						<div class="form-group row">
							<div class="col-sm-10 col-md-12">
								<button type="submit" class="btn btn-info w-100 mt-sm-4" tabindex="4" dmx-on:click="login.submit()">Submit
									<span class="spinner-grow spinner-grow-sm" role="status" dmx-show=""></span>
								</button>
							</div>
						</div>
						<div class="form-group row">
							<div class="col-sm-10 col-md-12 text-md-right">
								<small id="bs4-form-group-help1" class="form-text text-muted"><a href="/user/login.php">Already registered</a></small>
								<small id="bs4-form-group-help2" class="form-text text-muted"><a href="/user/requestpassword.php">Forgotten your password</a></small>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<?php include '../footer.html'; ?><script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
	<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>

The problem is in your submit button.
In HTML the submit button always submits the form. So you don’t need to add a dynamic event to it, which calls the form.submit again.

<button type="submit" class="btn btn-info w-100 mt-sm-4" tabindex="4" dmx-on:click="login.submit()">

This will cause the form to submit twice. Remove the onclick event and this will fix your issue.

2 Likes