Check and/or multiple profile options are filled?

Started by samborabora, July 16, 2014, 06:00:34 PM

Previous topic - Next topic

samborabora

#20
Quote from: margarett on July 17, 2014, 12:46:23 PM
Probably something like
if(($field['colname'] == 'cust_aboutm0') && !empty($field['value']))

Okay, trying something like this:
if (!isset($context['disabled_fields']['gender']) && !empty($context['member']['gender']['name']))
if(($field['colname'] == 'face_pro') && !empty($field['value']))
if(($field['colname'] == 'cust_last') && !empty($field['value']))
if(($field['colname'] == 'cust_soundc') && !empty($field['value']))
if(($field['colname'] == 'cust_twitte') && !empty($field['value']))
echo '
WORKS
';


But it doesn't work, how should I tie all these together?

margarett

Untested, can kill your forum, burn your house and drown your cat ;D

I assume you only want to know if either gender or one of the custom fields are filled, right?

If so:
//Control variable for the whole thing
$check = false;
//array with the list of custom fields that we want to check
$list_of_fields = array('face_pro', 'cust_last', 'cust_soundc', 'cust_twitte');

//Check for gender
if (!isset($context['disabled_fields']['gender']) && !empty($context['member']['gender']['name']))
$check = true;

//loop the loop
foreach ($context['custom_fields'] as $field)
{
if (!empty['value'] && in_array($field['colname'], $list_of_fields))
{
   $check = true;
   break;
}
}

//Finally...
if ($check)
  echo 'WORKS';
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 17, 2014, 07:27:44 PM
Untested, can kill your forum, burn your house and drown your cat ;D

I assume you only want to know if either gender or one of the custom fields are filled, right?

If so:
//Control variable for the whole thing
$check = false;
//array with the list of custom fields that we want to check
$list_of_fields = array('face_pro', 'cust_last', 'cust_soundc', 'cust_twitte');

//Check for gender
if (!isset($context['disabled_fields']['gender']) && !empty($context['member']['gender']['name']))
$check = true;

//loop the loop
foreach ($context['custom_fields'] as $field)
{
if (!empty['value'] && in_array($field['colname'], $list_of_fields))
{
   $check = true;
   break;
}
}

//Finally...
if ($check)
  echo 'WORKS';


Trying this, but I'm getting a syntax error on the comma between ['colname'], $list_of_fields What can I substitute it with?

Shambles

Try changing

if (!empty['value'] && in_array($field['colname'], $list_of_fields))

to this

if (!empty($field['value']) && in_array($field['colname'], $list_of_fields))

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Thank you so much, everyone, that works perfectly!! Now to see if the server crashes over time  ;D

samborabora

Here's the finished code for anyone that's interested:

//Control variable for the whole thing
$check = false;
//array with the list of custom fields that we want to check
$list_of_fields = array('face_pro', 'cust_last', 'cust_soundc', 'cust_twitte');

//Check for gender
if (!isset($context['disabled_fields']['gender']) && !empty($context['member']['gender']['name']))
$check = true;

//loop the loop
foreach ($context['custom_fields'] as $field)
{
if (!empty($field['value']) && in_array($field['colname'], $list_of_fields))
{
   $check = true;
   break;
}
}

//Finally...
if ($check)
  echo '
  <input id="hidiv" type="checkbox" value=""/>
  <label id="showlabel" for="hidiv" >More...</label>
  <div class="toshow">
  ';


Then have all of your custom fields and your gender display, and at the end of it, put:

if ($check)
  echo '</div>';


Here's the css, mine doesn't have a hide, just a show but any old show/hide css will do:
#hidiv {
   display:none;
}
#showlabel  {
  display:block;
  font-family: arial, verdana, sans-serif;
  font-size:12px;
  font-weight:bold;
  line-height:34px;
  cursor:pointer;
  clear:both;
}
.toshow ,
#hidiv:checked + label {
  display:none;
}
#hidiv:checked ~ .toshow {
  display:block;
}

I guess it could be modded to add other fields you want to show hide, the hardest part was getting all of the custom fields, the other stuff should be easier.

samborabora

One last thing, I've added the members age to the check, and it works, but unfortunately SMF decides to tell me that Age: n/a if there is no birthday set, which really I can't understand why it would do that when everything else here is as meaningful or meaningless to display as each other. How do i stop it from giving me the N/A back? This is the currently adjusted code I am using:

//Control variable for the whole thing
$check = false;
//array with the list of custom fields that we want to check
$list_of_fields = array('face_pro', 'cust_last', 'cust_soundc', 'cust_twitte');

//Check for age
if (!empty($context['member']['age']))
$check = true;

//Check for gender
if (!isset($context['disabled_fields']['gender']) && !empty($context['member']['gender']['name']))
$check = true;

//loop the loop
foreach ($context['custom_fields'] as $field)
{
if (!empty($field['value']) && in_array($field['colname'], $list_of_fields))
{
   $check = true;
   break;
}
}

//Finally...
if ($check)
  echo '
  <input id="hidiv" type="checkbox" value=""/>
  <label id="showlabel" for="hidiv" >More...</label>
  <div class="toshow">
  ';

if (!empty($context['member']['age']))
echo '
<dt style="margin-top:10px;">', $txt['age'], ':</dt>
<dd style="margin-top:10px;">', $context['member']['age'] . ($context['member']['today_is_birthday'] ? ' &nbsp; <img src="' . $settings['images_url'] . '/cake.png" alt="" />' : ''), '</dd>';


I cut the code after where it is relevant for this particular issue.

samborabora

Is N/A being stored in the mysql table, or is some other part reporting the age as N/A if the birthday value is empty? I really just want it to be a null value like all of the other options if it has nothing set rather than this N/A business.

margarett

Sources/Profile-View.php

// Set the age...
if (empty($context['member']['birth_date']))
{
$context['member'] += array(
'age' => $txt['not_applicable'],
'today_is_birthday' => false
);
}

Just have 'age' => '',
And it becomes empty ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 21, 2014, 06:23:00 AM
Sources/Profile-View.php

// Set the age...
if (empty($context['member']['birth_date']))
{
$context['member'] += array(
'age' => $txt['not_applicable'],
'today_is_birthday' => false
);
}

Just have 'age' => '',
And it becomes empty ;)

I tried that, and it just gave me a 1, lol! I changed it in:

index.english.php:
$txt['not_applicable'] = '';

If I find any missing N/A's around the board after doing this, I'll just make a new txt string, blank it and change the age to refer to that instead, thanks for your help!

Advertisement: