Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Gobo - helmikuu 13, 2006, 02:59:31 IP

Otsikko: Whats wrong with this code?
Kirjoitti: Gobo - helmikuu 13, 2006, 02:59:31 IP
hi

i am basically trying to get icons to show up next to a custom profile feild i created using [unknowns] tutorial on custom feilds...

ok this is the part where i have specified a drop down list in the persons profile where they can cnoose 1/7 options



</tr><tr>
<td><b>Way of Life: </b></td>
<td><select name="default_options[profile_way_of_life]">
<option', @$context['member']['options']['profile_way_of_life'] == 'Islam' ? ' selected="selected"' : '', '>Islam</option>
<option', @$context['member']['options']['profile_way_of_life'] == 'Christianity' ? ' selected="selected"' : '', '>Christianity</option>
<option', @$context['member']['options']['profile_way_of_life'] == 'Judaism' ? ' selected="selected"' : '', '>Judaism</option>
<option', @$context['member']['options']['profile_way_of_life'] == 'Buddhist' ? ' selected="selected"' : '', '>Buddhist</option>
<option', @$context['member']['options']['profile_way_of_life'] == 'Athiest' ? ' selected="selected"' : '', '>Athiest</option>
<option', @$context['member']['options']['profile_way_of_life'] == 'Undisclosed' ? ' selected="selected"' : '', '>Undisclosed</option>
<option', @$context['member']['options']['profile_way_of_life'] == 'Undecided' ? ' selected="selected"' : '', '>Undecided</option>
</select></td>
</tr>';



Up to here everything works fine after the modifications in the profile.template.php file

====================================

now the problem

In display.template.php

I tried to associate images with each of the options using this code:



if (!empty($message['member']['options']['profile_way_of_life']))
{
echo 'Way of Life: ', $message['member']['options']['profile_way_of_life'] , ' <img src="http://path-to-peace.net/forum/Themes/default/images/';
if ($message['member']['options']['profile_way_of_life'] == Christianity) {
echo 'Christianity.gif'
}
elseif ($message['member']['options']['profile_way_of_life'] == Islam)
{
echo 'Islam.gif'
}
elseif ($message['member']['options']['profile_way_of_life'] == Judaism)
{
echo 'Judaism.gif'
}
elseif ($message['member']['options']['profile_way_of_life'] == Buddhist)
{
echo 'Buddhist.gif'
}
elseif ($message['member']['options']['profile_way_of_life'] == Athiest)
{
echo 'Athiest.gif'
}
elseif ($message['member']['options']['profile_way_of_life'] == Undisclosed)
{
echo 'Undisclosed.gif'
}
elseif ($message['member']['options']['profile_way_of_life'] == Undecided)
{
echo 'Undecided.gif'
}
echo '"><br>';
}



but when i upload the file and try and load a post i get the error:

Lainaa

Template Parse Error!
There was a problem loading the /Themes/default/Display.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.


Any ideas whats wrong here?

Does anyone know of a simpler or shorter way for icons to appear for each of the options depending on the users choice?

PS: my images are stored in the /forum/Themes/default/images/ folder and named
Christianity, Islam. Athiestm Buddhist, etc etc etc (all .gif files)
Otsikko: Re: Whats wrong with this code?
Kirjoitti: Kindred - helmikuu 13, 2006, 04:20:15 IP
you are missing a semicolon after one of the echos...

why don't you do this:


if (empty($message['member']['options']['profile_way_of_life'])) {
    $message['member']['options']['profile_way_of_life']='Undisclosed';
}
echo '
   Way of Life: ', $message['member']['options']['profile_way_of_life'] , ' <img src="', $settings['images_url'], '/', $message['member']['options']['profile_way_of_life'], '.gif" /> <br />';


This will set everyone to "undisclosed" to begin with and then display the icon for their choice..

And, as for your first bit of code...    you can't have EVERY option selected!!!
Otsikko: Re: Whats wrong with this code?
Kirjoitti: fwitt - helmikuu 13, 2006, 04:52:09 IP
In the case where they hadent filled out there profile I'd just left it blank.

But apart from that Kindred has come up with pretty much the same code as I suggested originally here (http://www.smfarcade.net/index.php?topic=689.msg4636#msg4636).
which is nice to know as it means my understanding of php is improving.
Otsikko: Re: Whats wrong with this code?
Kirjoitti: Kindred - helmikuu 13, 2006, 05:24:48 IP
yes, Fwitt... not bad.

The only thing I would say is, don't forget the closing / in the various self-closing tags... for validation purposes.

<img ...   />
<br />
Otsikko: Re: Whats wrong with this code?
Kirjoitti: Gobo - helmikuu 13, 2006, 10:48:11 IP
fwitt I was to shy to ask u again - i kept asking and asking

and even afer all that couldnt get it to work so i felt really terrible to ask again

but guess what?

even after asking for help here the icons just dont show up!!!

So I give up!

no matter what I do it always only displays:

Way of Life: [selection]

where [selection] = the religion the person selected

the icon never shows up

just dont know whats going on so i give up

Thank you everyone for your kind help  :D
Otsikko: Re: Whats wrong with this code?
Kirjoitti: Gobo - helmikuu 13, 2006, 11:59:48 IP
its working its working!!!!!!!!!

Thank you so much Fwitt & kindered :D

basically I was making a mistake leaving out an "

and now it works yahoooooooooooo :D

Thank you
Otsikko: Re: Whats wrong with this code?
Kirjoitti: fwitt - helmikuu 14, 2006, 03:27:38 IP
Lainaus käyttäjältä: Kindred - helmikuu 13, 2006, 05:24:48 IP
yes, Fwitt... not bad.

The only thing I would say is, don't forget the closing / in the various self-closing tags... for validation purposes.

<img ...   />
<br />


ahhh was wondering what they did, normally would have put </img> etc tags but forgot in that code, didnt know there were self closing tags.

/me goes and edits the code on the other site.

Lainaus käyttäjältä: akulion - helmikuu 13, 2006, 10:48:11 IP

just dont know whats going on so i give up


never give up, the most likely problem is a simple syntax error or typo, if you feel like giving up paste the code to someone else, I always find its easier to spot mistakes in someone elses code, because when you wrote it you tend to see what you intended to write rather than what you actually wrote, its a perceptions thing.

Lainaus käyttäjältä: akulion - helmikuu 13, 2006, 11:59:48 IP
its working its working!!!!!!!!!

Thank you so much Fwitt & kindered :D

basically I was making a mistake leaving out an "

and now it works yahoooooooooooo :D

Thank you

no problem its always nice to see questions resolved.
In fact helping you has ment that Kindred has taught me something i didnt know before, its all a learning experience.