jbpeake
asked on
PHP auto execute a form
This should be easy, but I cannot figure it out. I have a form that allows people to log-in to a secure area, but for an odd reason I need to be able to make the form execute on it's own. So that when people click the "log in" link instead of getting the log in form, I want the page that holds the log in form to auto execute and send them on to the next page. I have included the form below. I tried just putting 'value="correct_username"' in for the username and the same for the password so that the user could just click on the submit button and get in, but that isn't what I need, I need the form to actually run without the user having to click the Submit button.
<form name="login_form" id="login" action="login.php" method="post"
onsubmit="return valid_form( this )">
<?php
if ( ! empty ( $return_path ) ) {
echo '<input type="hidden" name="return_path" value="' .
htmlentities ( $return_path ) . '" />' . "\n";
}
?>
<table align="center" cellspacing="10" cellpadding="10">
<tr><td rowspan="2">
<img src="images/login.gif" alt="Login" /></td><td align="right">
<label for="user"><?php etranslate ( 'Username' )?>:</label></td><td>
<input name="login" id="user" size="15" maxlength="25"
tabindex="1" />
</td></tr>
<tr><td class="alignright">
<label for="password"><?php etranslate ( 'Password' )?>:</label></td><td>
<input name="password" id="password" type="not_password" size="15"
maxlength="30" tabindex="2" />
</td></tr>
<tr><td colspan="3" style="font-size: 10px;">
<input type="checkbox" name="remember" id="remember" tabindex="3"
value="yes" <?php if ( ! empty ( $remember ) && $remember == 'yes' ) {
echo 'checked="checked"'; }?> /><label for="remember">
<?php etranslate ( 'Save login via cookies so I dont have to login next time.' )?></label>
</td></tr>
<tr><td colspan="4" class="aligncenter">
<input type="submit" value="<?php etranslate ( 'Login' )?>" tabindex="4" />
</td></tr>
</table>
</form>
ASKER
I gave it a try, but it isn't working... my new code is below... any suggestions?
<form name="login_form" id="login" action="login.php" method="post"
onsubmit="return valid_form( this )">
<?php
if ( ! empty ( $return_path ) ) {
echo '<input type="hidden" name="return_path" value="' .
htmlentities ( $return_path ) . '" />' . "\n";
}
?>
<table align="center" cellspacing="10" cellpadding="10">
<tr><td rowspan="2">
<img src="images/login.gif" alt="Login" /></td><td align="right">
<label for="user"><?php etranslate ( 'Username' )?>:</label></td><td>
<input name="login" id="user" size="15" maxlength="25"
tabindex="1" value="webadmin"/>
</td></tr>
<tr><td class="alignright">
<label for="password"><?php etranslate ( 'Password' )?>:</label></td><td>
<input name="password" id="password" type="not_password" size="15"
maxlength="30" tabindex="2" value="webadmin"/>
</td></tr>
<tr><td colspan="3" style="font-size: 10px;">
<input type="checkbox" name="remember" id="remember" tabindex="3"
value="yes" <?php if ( ! empty ( $remember ) && $remember == 'yes' ) {
echo 'checked="checked"'; }?> /><label for="remember">
<?php etranslate ( 'Save login via cookies so I dont have to login next time.' )?></label>
</td></tr>
<tr><td colspan="4" class="aligncenter">
<input type="submit" value="<?php etranslate ( 'Login' )?>" tabindex="4" />
</td></tr>
</table>
</form>
<?php
// Force autorun of form
if($_POST["submitbutton"])
{
?>
<script>
onload=autosubmit;
function autosubmit(){
document.getElementById('login').action='month.php';
document.getElementById('login').submit();
}
</script>
<?php
}
?>
This is all you need
<script>
document.getElementById('l ogin').sub mit();
</script>
<script>
document.getElementById('l
</script>
<form name="login_form" id="login" action="login.php" method="post"
onsubmit="return valid_form( this )">
<?php
if ( ! empty ( $return_path ) ) {
echo '<input type="hidden" name="return_path" value="' .
htmlentities ( $return_path ) . '" />' . "\n";
}
?>
<table align="center" cellspacing="10" cellpadding="10">
<tr><td rowspan="2">
<img src="images/login.gif" alt="Login" /></td><td align="right">
<label for="user"><?php etranslate ( 'Username' )?>:</label></td><td>
<input name="login" id="user" size="15" maxlength="25"
tabindex="1" value="webadmin"/>
</td></tr>
<tr><td class="alignright">
<label for="password"><?php etranslate ( 'Password' )?>:</label></td><td>
<input name="password" id="password" type="not_password" size="15"
maxlength="30" tabindex="2" value="webadmin"/>
</td></tr>
<tr><td colspan="3" style="font-size: 10px;">
<input type="checkbox" name="remember" id="remember" tabindex="3"
value="yes" <?php if ( ! empty ( $remember ) && $remember == 'yes' ) {
echo 'checked="checked"'; }?> /><label for="remember">
<?php etranslate ( 'Save login via cookies so I dont have to login next time.' )?></label>
</td></tr>
<tr><td colspan="4" class="aligncenter">
<input type="submit" value="<?php etranslate ( 'Login' )?>" tabindex="4" />
</td></tr>
</table>
</form>
<script>
document.getElementById('login').submit();
</script>
the code block i've last sent works.
But with onsubmit="return valid_form( this )" in form tag i cannot test it, could you please write us the valid_form function?
There is the code block to fail second submit i guess.
But with onsubmit="return valid_form( this )" in form tag i cannot test it, could you please write us the valid_form function?
There is the code block to fail second submit i guess.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
would you please run page without return valid_form( this ) checking and tell us if there is still any problem
Open in new window