Welcome Guest [Log In] [Register]
Add Reply
Show email; Users can hide or show their email
Topic Started: Jul 22 2008, 07:06 PM (330 Views)
JakkyD
Member Avatar

First I added "show_email" to my database via php my admin.

Code:
 

Field Type Collation Attributes Null Default Extra
show_email varchar(3) utf8_general_ci No no


I then added this extra field and its functions. You can find how to add new fields here Add New Fields Remember to name it show_email or subshow_email.

Add this to both useredit and register

Code:
 
<tr><td><p>Show email?</p></td><td><select name="show_email"><option selected="selected" value="no">No</option><option value="yes">Yes</option></select></td><td></td></tr>


You can obviously change it around i.e. value to <?echo $form->value("show_email"); ?>

Then on userinfo add this:

Code:
 
if ($req_user_info["show_email"] == yes) {
$output = "<p>". $req_user_info["email"] ."</p>";
} else {
$output = "<p>Address is hidden.</p>";
}

print $output;


Small but handy if your users want privacy.

If it doesnt work for anyone, just say, and I will paste all what I did.

P.s. You can just have this on useredit but I put it on register so that users can decide when they first sign up.

Also if you really want, you can put on userinfo an " if admin" statement displaying their email incase its hidden.
Edited by JakkyD, Jul 22 2008, 07:34 PM.
Offline Profile Quote Post Goto Top
 
scottjcampbell
Member Avatar

Yes, i have made it so if the user is an Administrator, or if it is their own account, they are allowed to see it, like this:
Code:
 
if ($req_user_info["show_email"] == yes) {
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}
else{
if(strcmp($session->username,$req_user) == 0){
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}
else{
if($session->isAdmin()){
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}}}
?>
Offline Profile Quote Post Goto Top
 
feartec

sorry, but i don't think that will work, you used twice the else statement.
It will give the error: Unexpected t_else.

What you can do is:

Code:
 

if ($req_user_info["show_email"] == yes) {
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}
else if(strcmp($session->username,$req_user) == 0){
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}
else{
if($session->isAdmin()){
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}}}
?>

then you use the if, else if and else statement. That must work.
Edited by feartec, Jul 23 2008, 03:23 PM.
Offline Profile Quote Post Goto Top
 
scottjcampbell
Member Avatar

feartec
Jul 23 2008, 11:31 AM
sorry, but i don't think that will work, you used twice the else statement.
It will give the error: Unexpected t_else.

What you can do is:

Code:
 

if ($req_user_info["show_email"] == yes) {
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}
else if(strcmp($session->username,$req_user) == 0){
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}
else{
if($session->isAdmin()){
echo "<img border=\"0\" src=\"/Images/email.png\">".$req_user_info['email']."<br></p>";
}}}
?>

then you use the if, else if and else statement. That must work.
It worked for me?
Offline Profile Quote Post Goto Top
 
feartec

ok, weird. :P, keep up the greet work.
Offline Profile Quote Post Goto Top
 
laurens

I have a little problem..
In this line.. <tr><td><p>Show email?</p></td><td><select name="show_email"><option selected="selected" value="no">No</option><option value="yes">Yes</option></select></td><td></td></tr> how can I sent the yes or no value to the database, because it stayes with an empty value?
Offline Profile Quote Post Goto Top
 
Vimto

Like he says in the original post, you have to follow the instructions for adding an extra field to a users profile.

Here: http://s1.zetaboards.com/jpsystem/topic/154960/1/
Offline Profile Quote Post Goto Top
 
quimkaos

why are you guys using yes and no?? why not 1 or 0??
i'm using this but with at least true and false statements .... 0/1 true/false
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Other · Next Topic »
Add Reply