Now that we have modified the registration form with new option field country, it's time to edit userinfo.php and useredit.php.
userinfo.php
Open the file userinfo.php for editing, and add this code.
we loop throught the countryArray() that we have created in the part 1 of this how-to.
we asign $key and $value and check if there a match with requested user infos.
useredit.php
Open the file useredit.php for editing, and add this code.
Almost as previous, but we loop each value in array and assign selected if match form value
or request user info.
process.php
just add $_POST['country'] argument to the $session->editaccount() class.
session.php
Add $subcountry argument to the editAccount() function.
Check for empty option seletion.
if no erro occured update the batabase
That's it your done.
userinfo.php
Open the file userinfo.php for editing, and add this code.
we loop throught the countryArray() that we have created in the part 1 of this how-to.
we asign $key and $value and check if there a match with requested user infos.
- Code:
/* Country */
foreach (countryArray() as $key => $value) if($req_user_info['country'] == $key) $country = $value;
echo "<b>Country:</b> ".$country."<br>";
useredit.php
Open the file useredit.php for editing, and add this code.
Almost as previous, but we loop each value in array and assign selected if match form value
or request user info.
- Code:
<tr>
<td>Country:</td><td><select size="1" name="country">
<option value=""></option>
<?
foreach (countryArray() as $key => $value) {
if($form->value("country") == $key || $session->userinfo['country'] == $key) $selected = "selected";
print '<option value="'.$key.'" ' . $selected . '>' . $value . '</option>';
$selected = '';
}
?>
</select></td>
<td><? echo $form->error("country"); ?></td>
</tr>
process.php
just add $_POST['country'] argument to the $session->editaccount() class.
- Code:
/**
* procEditAccount - Attempts to edit the user's account
* information, including the password, which must be verified
* before a change is made.
*/
function procEditAccount(){
global $session, $form;
/* Account edit attempt */
$retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email'], $_POST['firstname'], $_POST['country']);
/* Account edit successful */
if($retval){
$_SESSION['useredit'] = true;
header("Location: ".$session->referrer);
}
/* Error found with form */
else{
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
}
session.php
Add $subcountry argument to the editAccount() function.
- Code:
function editAccount($subcurpass, $subnewpass, $subemail, $subfirstname, $subcountry){
...
Check for empty option seletion.
- Code:
/*Country error checking */
$field = "country";
if($subcountry == '') $form->setError($field, "* country not entered");
...
if no erro occured update the batabase
- Code:
/* Change Country */
if($subcountry) $database->updateUserField($this->username,"country",$subcountry);
That's it your done.
Last edited by Fred-Eric on Sat Mar 14, 2009 7:52 pm; edited 2 times in total