Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Convert v7 Userfield To v9

Asked Modified Viewed 1,813 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

I need help converting a v7 userfield to a v9 userfield. There are no existing v9 userfields from which to base my conversion and to my knowledge there are no Online Guides for doing so. Here is the v7 userfield include file:
if (!defined("IN_FUSION")) { die("Access Denied"); }

if ($profile_method == "input") {
   echo "<tr>n";
   echo "<td class='tbl'>".$locale['uf_autonews_001'].":</td>n";
   echo "<td class='tbl'><input type='checkbox' name='user_autonews' class='checkbox' ".(isset($user_data['user_autonews']) && $user_data['user_autonews'] == "1"? "checked='checked'": "")." /></td>n";
   echo "</tr>n";
} elseif ($profile_method == "display") {
   if ($user_data['user_autonews']) {
      echo "<tr>n";
      echo "<td width='1%' class='tbl1' style='white-space:nowrap'>".$locale['uf_autonews_001']."</td>n";
      echo "<td align='right' class='tbl1'>".($user_data['user_autonews'] == "1" ? $locale['uf_autonews_002'] : $locale['uf_autonews_003'])."n";
      echo "</td>n</tr>n";
   }
} elseif ($profile_method == "validate_insert") {
   $db_fields .= ", user_autonews";
   $db_values .= (", '".(isset($_POST['user_autonews'])? 1 : 0)."'");
} elseif ($profile_method == "validate_update") {
   $db_values .= (", user_autonews='".(isset($_POST['user_autonews'])? 1: 0)."'");
}
?>

And this is my beginning of an attempt to convert it. Of course it's incomplete:
defined('IN_FUSION') || exit;

if ($profile_method == "input") {

/*
 * Field Value
 * 0 No
 * 1 Yes
 */

$autonews_options = [
 0 => $locale['uf_autonews_no'],
 1 => $locale['uf_autonews_yes'],
];

   $input_type = 'form_checkbox';

} elseif ($profile_method == "display") {

Any help would be appreciated.
Edited by Grimloch on 21-02-2022 17:04,
0 replies

6 posts

R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

I assume this is option that is visible only for that user so you don't need to display it on profile.

This is all you need
defined('IN_FUSION') || exit;

if ($profile_method == "input") {
   $options = [
      'toggle' => TRUE,
   ] + $options;
   $user_fields = form_checkbox('user_autonews', $locale['uf_autonews_001'], $field_value, $options);
}


It's not that hard, just open any core user fields and see how it works.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Actually it does need to be displayed in profile as this is a YES/NO to subscribe to receive autonews updates. Needs the option also to add it to the registration form.
0 replies
R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

Only this code you need to display input in edit profile /register nothing else.

if ($profile_method == "input") { is for edit profile/register

So as i said it's option just for currently logged in user/ or in register form. If you add input to $profile_method == "display" it will be in public profile = editable for all
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

OK RobiNN thanks, I'll give it a shot. smile
0 replies
R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

It's easy if the field is editable only for the logged in user then it must be in if ($profile_method == "input") {, in user fields administration you can check this field as required and display it on register form as well.

} elseif ($profile_method == "display") { - This is content visible for all when you visit profile.

This your code shows what that user has set. Another unnecessary thing that doesn't need to appear in a public profile
} elseif ($profile_method == "display") {
if ($user_data['user_autonews']) {
echo "<tr>n";
echo "<td width='1%' class='tbl1' style='white-space:nowrap'>".$locale['uf_autonews_001']."</td>n";
echo "<td align='right' class='tbl1'>".($user_data['user_autonews'] == "1" ? $locale['uf_autonews_002'] : $locale['uf_autonews_003'])."n";
echo "</td>n</tr>n";
}
}


So only you need is input visible in edit profile/register

Try code and you will see what I mean.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Well it works great RobiNN and thanks as always !! smile
0 replies

Category Forum

User Fields - 9

Labels

Statistics

  • Views 0 views
  • Posts 6 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
R
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet