...

View Full Version : Form Entry and Redirection!



onthespot
08-29-2007, 12:19 AM
Ok, i've tried to work this one out on my own. Really wanted to. But I really can't! The problem is that on my site, the user needs to be able to change their password, so on the page where i've put the form to change it, the address is (/usersettings.php?user=$session->username). This obviously means their username goes on the end of the address. However, when the form is submitted, it redirects the user to (/usersettings.php), without the (?user=$session->username) on the end. This is where the problem is lying, because then the user is getting an error message, saying "Username Not Found".

I've included the code;
Firstly the HTML:


<?

if(isset($_SESSION['usersettings'])){
unset($_SESSION['usersettings']);

echo "<h1>User Account Edit Success!</h1>";
echo "<p><b>$session->username</b>, your account has been successfully updated. "
."<a href=\"main.php\">Main</a>.</p>";
}
else{
?>

<?

if($session->logged_in){
?>
</span>
<h1 class="style1">User Account Edit : <? echo $session->username; ?></h1>
<span class="style1">
<?
if($form->num_errors > 0){
echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
</span>
<form action="process.php" method="POST" class="style1">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>Current Password:</td>
<td><input type="password" name="curpass" maxlength="30" value="
<?echo $form->value("curpass"); ?>"></td>
<td><? echo $form->error("curpass"); ?></td>
</tr>
<tr>
<td>New Password:</td>
<td><input type="password" name="newpass" maxlength="30" value="
<? echo $form->value("newpass"); ?>"></td>
<td><? echo $form->error("newpass"); ?></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" maxlength="50" value="
<?
if($form->value("email") == ""){
echo $session->userinfo['email'];
}else{
echo $form->value("email");
}
?>"></td>
<td><? echo $form->error("email"); ?></td>
</tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subedit" value="1">
<input type="submit" value="Edit Account"></td></tr>
<tr><td colspan="2" align="left"></td></tr>
</table>
</form>

<span class="style1">
<?
}
}

?>

As you see in bold, the form is submitted to process.php

Here is the PHP code for this form.


function procEditAccount(){
global $session, $form;

$retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);


if($retval){
$_SESSION['usersettings'] = true;
header("Location: ".$session->referrer);
}

else{
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}

If there are any errors in the PHP, its because its the snippet from the entire process.php that actual matters to this particular the form. Could anyway help me make the form redirect back to the page it is submitted from! With the (?user=$session->username) on the end?

Any help would be greatly appreciated!
Thanks!

Mwnciau
08-29-2007, 12:26 AM
$session->referrer .= (preg_match('#\?#', $session->referrer)) ? '&user='.$session->username : '?user='.$session->username;
header("Location: ".$session->referrer);

OR if you want all of the URL variables carried on


$session->referrer .= (preg_match('#\?#', $session->referrer)) ? '&'.$_SERVER['QUERY_STRING'] : '?'.$_SERVER['QUERY_STRING'] ;
header("Location: ".$session->referrer);

onthespot
08-29-2007, 01:17 AM
hey mate, which one does what different?? and where do i add it?
thanks

Mwnciau
08-29-2007, 01:22 AM
Use this to redirect with the user variable in the URL


function procEditAccount(){
global $session, $form;

$retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);


if($retval){
$_SESSION['usersettings'] = true;
$session->referrer .= (preg_match('#\?#', $session->referrer)) ? '&user='.$session->username : '?user='.$session->username;
header("Location: ".$session->referrer);
}

else{
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
$session->referrer .= (preg_match('#\?#', $session->referrer)) ? '&user='.$session->username : '?user='.$session->username;
header("Location: ".$session->referrer);
}

onthespot
08-29-2007, 01:37 AM
thanks a lot, got it working now! cheers! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum