Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2010, 09:30 AM
Mark.B Mark.B is offline
Senior Member
 
Join Date: Feb 2004
Posts: 1,354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help getting custom stylechoose code to work

Some time ago, after much messing about, I managed to get the code in THIS thread to work on my live site.

What this does is change the style chooser dropdown (for members) so that instead of setting a cookie, it actually updates the user profile.

However, despite replicating the template code exactly using vB4-style variables, I can't get it to work. It seems to submit the form but redirects back to index.php instead of staying on the page it was on, but doesn't actually change the style. That suggests that the $show['member'] conditional is returning false, but even if I totally remove that conditional and just leave the code to be executed on submitting the form, it still does the same thing.

I've tried comparing the code with other files in vB4 and it seems correct, so I can't work out what's missing. I'm sure it's something simple.

Here's the contents of my file myprofile.php:

Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'myprofile');
define('CSRF_PROTECTION', true);

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// ############################### start update options ###############################
if ($_POST['do'] == 'updateoptions')
{
    if ($show['member']){

        $vbulletin->input->clean_array_gpc('p', array('newstyleset'    => TYPE_INT));

        $userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
        $userdata->set_existing($vbulletin->userinfo);

        // style set
        if ($vbulletin->options['allowchangestyles'] AND $vbulletin->userinfo['realstyleid'] != $vbulletin->GPC['newstyleset'])
        {
            $userdata->set('styleid', $vbulletin->GPC['newstyleset']);
        }

        ($hook = vBulletinHook::fetch_hook('profile_updateoptions')) ? eval($hook) : false;
        $userdata->save();
    }
    else {
         exec_header_redirect("../index.php?");
    }
}

// #############################################################################
$url = $_SERVER['HTTP_REFERER'];
exec_header_redirect($_SERVER['HTTP_REFERER']);

?>
And here's the code I'm using in the footer template to power the style chooser, this is basically an exact replication from the vB3 site but with the relevant compatibility changes for vB4:

Code:
<vb:if condition="$show['quickchooser']">
<vb:if condition="$bbuserinfo['userid']">
<form style="display: inline" action="myprofile.php" method="post" >
<input type="hidden" name="s" value="" />
<input type="hidden" name="do" value="updateoptions" />
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<select class="forumselector" name="newstyleset" id="sel_newstyleset"  onchange="this.form.submit()";>
<optgroup label="{vb:rawphrase quick_style_chooser}">
{vb:raw quickchooserbits}
</optgroup>						             
</select>
</vb:if>	
</vb:if>
I have wrestled with this one on and off for weeks and cannot fathom what is wrong.

Can anybody spot what needs changing? If pointed in the right direction I'm sure I'm savvy enough to sort it!
Reply With Quote
  #2  
Old 11-28-2010, 03:25 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Two things.... first, you didn't put it inside the other form that is originally there, did you? Also, I think you mean onchange="this.form.submit();"
Reply With Quote
  #3  
Old 11-28-2010, 07:41 PM
Mark.B Mark.B is offline
Senior Member
 
Join Date: Feb 2004
Posts: 1,354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Lynne...I knew you'd suss it! It was inside the other form, I forgot about the language chooser (which I don't use).

I also changed the onchange code on the live 3.8 site too, although it was working, the syntax was clearly wrong.

All working now.
Reply With Quote
  #4  
Old 11-28-2010, 07:54 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great!
Reply With Quote
  #5  
Old 11-28-2010, 11:01 PM
Mark.B Mark.B is offline
Senior Member
 
Join Date: Feb 2004
Posts: 1,354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm pleased about this one, I have never liked the "cookie based" system of style choosing, it confuses people. I am never sure quite why vB have stuck with it for so long.

Cookie based is fine for guests but not for members.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:05 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08623 seconds
  • Memory Usage 2,202KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete