Support Support - 1 year ago 44
HTML Question

How to fix this error: Nested forms are not allowed

I have this code in my open source script:

<form id="thisform" method="post">
<p class="right-text-al-rtl">{#Login_Have_Account#}</p>
<form action="{$URL_login}" method="post">
<strong>{#Username#}/{#Email#}:</strong><br />
<input autofocus="autofocus" type="text" name="username" class="form-control" value="{if isset($login_username)}{$login_username}{/if}" tabindex="1" /><br />

<strong>{#Password#}:</strong><br />
<input type="password" name="password" class="form-control" tabindex="2" /><br />
<input type="hidden" name="processlogin" value="1"/>
<input type="hidden" name="return" value="{if isset($get.return)}{$get.return}{/if}"/>
<div class="login-submit">
<input type="submit" value="{#LoginButton#}" class="btn btn-primary" tabindex="4" />
<div class="login-remember">
<input type="checkbox" class="col-sm-offset-2" name="persistent" tabindex="3" /> {#Login_Remember#}

The programmer of this script used two forms, one inside the other. This is not correct, but how can I fix this error and update my open source script?

Answer Source

The outer form tag has no submit button, so based on this snippet it is safe to remove the outer form. To do this remove the <form id... line and the last </form> tag.

However, note that because the form carries an id, it is possible that it is being targeted by either CSS or Javascript in a way that is impossible to predict without seeing the entire codebase. The best thing to do is to remove it and test it for any regressions.