So I am still struggling with this issue. When the user name is not in use, the form is not forwarding to the posting URL. For a recap:
- User fills in form with user name.
- Form submits to itself.
- Check for in use user name.
- If user name is in use, return form with error message set to submit to itself.
- If user name is not in use, change the post variable to post to processing URL (on a server out of my control.)
#5 is usually where I come into the problem. Whether or not this is the user's first or subsequent submit, the code runs through the block that would change the posting URL, but the page doesn't automatically forward with the JavaScript. So, below is my code. Any suggestions, recommendations, etc... are highly appreciated:
<?
$post_action = "$PHP_SELF";
//Pull user id from cookie
$xnum = $HTTP_COOKIE_VARS['bbuserid'];
//Check if user is cookied
If (!empty($xnum)) {
//Connect to database server
$dbcnx = @mysql_connect($db_server, $db_server_user, $db_server_user_password);
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
}
//Select the TAPN database
if (! @mysql_select_db($db_database) ) {
die( '<p>Unable to locate the nuke ' .
'database at this time.</p>' );
}
//Get user data from database to fill in form fields
$query = "SELECT username, email, field2, field3, field4, field6, field7, field8, field9, field10, field11, field12
FROM user, userfield
WHERE user.userid = userfield.userid
AND userfield.userid = $xnum;";
$result = mysql_query($query);
$row_value = mysql_fetch_array($result);
//Set form processing information
$post_action = "join-results-yw.php";
}//end of 'if cookie' check
//Check user name entry against database records
if ($submit == "Start My Membership Now") {
$error_msg = "";
//Connect to database server
$dbcnx = @mysql_connect($db_server, $db_server_user, $db_server_user_password);
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
}
//Select the TAPN database
if (! @mysql_select_db($db_database) ) {
die( '<p>Unable to locate the nuke ' .
'database at this time.</p>' );
}
//Check for existing username
$query = "SELECT username FROM user WHERE username = '$username';";
$result = mysql_query($query);
//if username already exists in database
if (mysql_num_rows($result) > 0) {
//setup error message
$error_msg = "<p class="error">Error: The username you selected is already in use. Please select another username.</p>";
} else {
//set variable for automatic form posting
$post_action = "join-results-yw.php";
$jscript_submit = " onLoad=\"javascript:void(document.frmMain.submit())\"";
}
}
?>
Now, these are the two different javascript solutions I've tried, the first with the "onLoad" handler in the body tag:
<body bgcolor="#FFFFFF" text="#000000"<?=$jscript_submit; ?>>
And the second without the "onLoad" handler in the body tag, but with a script to submit after the forms have been loaded:
<script type="javascript">
<!--
<?
if ($post_action == "join-results-yw.php") { ?>
document.frmMain.submit();
document.subform.submit(); <?
}
?>
//-->
</script>
Help! 😐