phpBB3 AJAX
Posted March 18th 2015, 9:03pm
Dion said:
That's because when sending an AJAXified form, you must embed the AJAX-based functions into the form. You can look at confirm_body.html for an example of this.

However, since I've been gone for a while, I feel the need to do something nice. :) Here is an AJAXified version of report_body.html:

<!-- IF NOAJAX -->

<!-- INCLUDE overall_header.html -->

<h2 class="titlespace"><!-- IF S_REPORT_POST -->{L_REPORT_POST}<!-- ELSE -->{L_REPORT_MESSAGE}<!-- ENDIF --></h2>

<form method="post" action="{S_REPORT_ACTION}" id="report">
<div class="panel">
<div class="inner"><span class="corners-top"><span></span></span>
<div class="content">

<!-- ELSE -->
<style type="text/css">#report select,#report option{max-width:300px}</style>
<h2 class="titlespace"><!-- IF S_REPORT_POST -->{L_REPORT_POST}<!-- ELSE -->{L_REPORT_MESSAGE}<!-- ENDIF --></h2>

<form method="post" action="{S_REPORT_ACTION}" id="report" style="max-width:600px">
<!-- ENDIF -->

<p><!-- IF S_REPORT_POST -->{L_REPORT_POST_EXPLAIN}<!-- ELSE -->{L_REPORT_MESSAGE_EXPLAIN}<!-- ENDIF --></p>

<fieldset<!-- IF not NOAJAX --> class="fields1"<!-- ENDIF -->>
<dl<!-- IF NOAJAX --> class="fields2"<!-- ENDIF -->>
<dt><label for="reason_id">{L_REASON}:</label></dt>
<dd><select name="reason_id" id="reason_id" class="full"><!-- BEGIN reason --><option value="{reason.ID}"<!-- IF reason.S_SELECTED --> selected="selected"<!-- ENDIF -->>{reason.DESCRIPTION}</option><!-- END reason --></select></dd>
</dl>
<!-- IF S_CAN_NOTIFY -->
<dl<!-- IF NOAJAX --> class="fields2"<!-- ENDIF -->>
<dt><label for="notify1">{L_REPORT_NOTIFY}:</label><br /><span>{L_REPORT_NOTIFY_EXPLAIN}</span></dt>
<dd>
<label for="notify1"><input type="radio" name="notify" id="notify1" value="1" <!-- IF not S_NOTIFY -->checked="checked"<!-- ENDIF --> /> {L_YES}</label>
<label for="notify0"><input type="radio" name="notify" id="notify0" value="0" <!-- IF S_NOTIFY -->checked="checked"<!-- ENDIF --> /> {L_NO}</label>
</dd>
</dl>
<!-- ENDIF -->
<dl<!-- IF NOAJAX --> class="fields2"<!-- ENDIF -->>
<dt><label for="report_text">{L_MORE_INFO}:</label><br /><span>{L_CAN_LEAVE_BLANK}</span></dt>
<dd><textarea name="report_text" id="report_text" rows="10" cols="76" class="inputbox">{REPORT_TEXT}</textarea></dd>
</dl>
</fieldset>

<!-- IF NOAJAX -->
</div>

<span class="corners-bottom"><span></span></span></div>
</div>

<div class="panel">
<div class="inner"><span class="corners-top"><span></span></span>

<div class="content">
<fieldset class="submit-buttons">
<input type="submit" name="submit" class="button1" value="{L_SUBMIT}" /> 
<input type="submit" name="cancel" class="button2" value="{L_CANCEL}" />
{S_FORM_TOKEN}
</fieldset>
</div>

<span class="corners-bottom"><span></span></span></div>
</div>
</form>

<!-- INCLUDE overall_footer.html -->

<!-- ELSE -->
<fieldset class="submit-buttons">
<input type="button" value="{L_SUBMIT}" class="button1" onclick="$.post('{S_REPORT_ACTION}',$('#report').serialize()+'&ajax=y&submit=Submit',function(data){$('#msg-ajax').html(data);set_ajaxbox();})" /> 
<input type="button" value="{L_CANCEL}" class="button2" onclick="ajaxbox_off()" />
{S_FORM_TOKEN}
</fieldset>
</form>
<!-- ENDIF -->

Enjoy!


I tried this and it doesn't work. It still takes me to the report page but there's no Ajaxifying stuff :/ It works as it normally does..
φ
Posts: 103
Joined: July 19th 2012, 8:17pm
Location: Pennsylvania
Likes Given: 9
Likes Received: 8
phpBB3 AJAX
Posted March 19th 2015, 1:02pm
That's probably because you didn't add the data-ajax="" attribute to the report button. ;)

I just AJAXified the report screen here so you can see what it looks like. Here is the exact report_body.html template that is being used:

<!-- IF NOAJAX -->

<!-- INCLUDE overall_header.html -->

<h2 class="titlespace"><!-- IF S_REPORT_POST -->{L_REPORT_POST}<!-- ELSE -->{L_REPORT_MESSAGE}<!-- ENDIF --></h2>

<form method="post" action="{S_REPORT_ACTION}" id="report">
<div class="panel">
<div class="inner"><span class="corners-top"><span></span></span>
<div class="content">

<!-- ELSE -->
<style type="text/css">h2{margin:10px 0}dl{text-align:left}#report select,#report option{max-width:300px}</style>
<h2><!-- IF S_REPORT_POST -->{L_REPORT_POST}<!-- ELSE -->{L_REPORT_MESSAGE}<!-- ENDIF --></h2>

<form method="post" action="{S_REPORT_ACTION}" id="report" style="max-width:600px">
<!-- ENDIF -->

<p><!-- IF S_REPORT_POST -->{L_REPORT_POST_EXPLAIN}<!-- ELSE -->{L_REPORT_MESSAGE_EXPLAIN}<!-- ENDIF --></p>

<fieldset class="fields2">
<dl>
<dt><label for="reason_id">{L_REASON}:</label></dt>
<dd><select name="reason_id" id="reason_id" class="full"><!-- BEGIN reason --><option value="{reason.ID}"<!-- IF reason.S_SELECTED --> selected="selected"<!-- ENDIF -->>{reason.DESCRIPTION}</option><!-- END reason --></select></dd>
</dl>
<!-- IF S_CAN_NOTIFY -->
<dl>
<dt><label for="notify1">{L_REPORT_NOTIFY}:</label><br /><span>{L_REPORT_NOTIFY_EXPLAIN}</span></dt>
<dd>
<label for="notify1"><input type="radio" name="notify" id="notify1" value="1" <!-- IF not S_NOTIFY -->checked="checked"<!-- ENDIF --> /> {L_YES}</label>
<label for="notify0"><input type="radio" name="notify" id="notify0" value="0" <!-- IF S_NOTIFY -->checked="checked"<!-- ENDIF --> /> {L_NO}</label>
</dd>
</dl>
<!-- ENDIF -->
<dl>
<dt><label for="report_text">{L_MORE_INFO}:</label><br /><span>{L_CAN_LEAVE_BLANK}</span></dt>
<dd><textarea name="report_text" id="report_text" rows="10" cols="76" class="inputbox">{REPORT_TEXT}</textarea></dd>
</dl>
</fieldset>

<!-- IF NOAJAX -->
</div>

<span class="corners-bottom"><span></span></span></div>
</div>

<div class="panel">
<div class="inner"><span class="corners-top"><span></span></span>

<div class="content">
<fieldset class="submit-buttons">
<input type="submit" name="submit" class="button1" value="{L_SUBMIT}" />
<input type="submit" name="cancel" class="button2" value="{L_CANCEL}" />
{S_FORM_TOKEN}
</fieldset>
</div>

<span class="corners-bottom"><span></span></span></div>
</div>
</form>

<!-- INCLUDE overall_footer.html -->

<!-- ELSE -->
<fieldset class="submit-buttons">
<input type="button" value="{L_SUBMIT}" class="button1" onclick="$.post('{S_REPORT_ACTION}',$('#report').serialize()+'&ajax=y&submit=Submit',function(data){$('#msg-ajax').html(data);set_ajaxbox();})" />
<input type="button" value="{L_CANCEL}" class="button2" onclick="ajaxbox_off()" />
{S_FORM_TOKEN}
</fieldset>
</form>
<!-- ENDIF -->
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
phpBB3 AJAX
Posted March 19th 2015, 2:47pm
Ah, yes of course. Thanks!
φ
Posts: 103
Joined: July 19th 2012, 8:17pm
Location: Pennsylvania
Likes Given: 9
Likes Received: 8
phpBB3 AJAX
Posted June 28th 2015, 3:00am
Daniel said:
Just the heads up, I got it working last night and I love it.

Now I used $_profile_cache['tpl_profile_colour'] = '<a href="{PROFILE_URL}" onclick="ajaxbox_on();$.get(\'{PROFILE_URL}&ajax=y\',function(data){$(\'#msg-ajax\').html(data);set_ajaxbox();});return false"; style="color:{USERNAME_COLOUR}" class="username-coloured">{USERNAME}</a>'; and that does the job for me.

Please note that if you are going to do this, it will apply to every theme that you got installed, and you may get errors if you can't apply the javascript and css to your overall_header.html file.


Hi
I replaced this:
$_profile_cache['tpl_profile_colour'] = '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';

with your code but I can`t see it to work...nothing happens :( ..cleared cache and everything.
Can you help ? Thank you!

P.S. Is there a way I can add ajax from php to all info or error messages ? I`m using one theme only. I have a lot of mods and can`t add ajax to all from html. And I`m not good at coding either.
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted June 28th 2015, 1:50pm
That code would require the AJAXify MOD (from this topic) to be installed, as well as modifications to the memberlist_view.html template so the "&ajax=y" part of the URL would work properly. It also requires jQuery.
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
phpBB3 AJAX
Posted July 2nd 2015, 7:37am
Thank you for reply! . I installed the mod but I can`t find what modifications I have to do in memberlist_view.html :( . can you help ? Thank you!.
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted July 2nd 2015, 1:15pm
You'll find the instructions in this post: /p13482/#p13482
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
phpBB3 AJAX
Posted July 2nd 2015, 2:57pm
Thaank you, I tried that but it`s working only if I click from postprofile field, in the left side of the post. If I click on the profile name from somewhere else, I get redirected to the old profile page. Any help ? Maybe I`m doing something wrong in functions_content.php ?! I can`t tell :(
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted July 2nd 2015, 9:10pm
Please read this and the next four posts: /p13709/#p13709
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
phpBB3 AJAX
Posted July 2nd 2015, 11:17pm
I did :), I entered the php code but it doesn't work :/ I don't know what I'm missing. Sorry for my bad english.
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted July 5th 2015, 4:45am
Any help please? I have no idea how to make it work :( and I need this . The website is the ore from my profile
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted July 6th 2015, 9:10am
There isn't anything more I can do because I have no idea what you mean by "it doesn't work". What doesn't work? Do you get any errors in the javascript console? Does the lightbox appear with an empty box or the animated waiting icon? (I cannot check myself because profiles can only be viewed by members.)
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
phpBB3 AJAX
Posted July 6th 2015, 9:39am
forforce said:
Thaank you, I tried that but it`s working only if I click from postprofile field, in the left side of the post. If I click on the profile name from somewhere else, I get redirected to the old profile page. Any help ? Maybe I`m doing something wrong in functions_content.php ?! I can`t tell :(

The same in memberlist too. It`s like Daniel code is not functioning for me :(
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted July 6th 2015, 10:03am
The code I provided only works in post profiles. If you want the popup for all usernames, you will need to use Daniel's code (which belongs in the get_username_string() function in includes/functions_content.php). Make sure it is all on one line -- if you split it on multiple lines it will not work.
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
phpBB3 AJAX
Posted July 6th 2015, 12:15pm
I know , I did that , no effect. This is how it looks like: http://postimg.org/image/wzlb69akh
One more thing...If I`m not logged in, I get a white page when I click on profile from post profiles
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted July 6th 2015, 4:55pm
First, remove the changes to the post profile in viewtopic_body.html if you are also using the change to get_username_string() in includes/functions_content.php. If you have both, you will have problems. :)

Second, there is a mistake in Daniel's code. Please use the following:

		$_profile_cache['tpl_profile_colour'] = '<a href="{PROFILE_URL}" onclick="ajaxbox_on();$.get(\'{PROFILE_URL}&ajax=y\',function(data){$(\'#msg-ajax\').html(data);set_ajaxbox();});return false" style="color:{USERNAME_COLOUR}" class="username-coloured">{USERNAME}</a>';

And finally, when you change that line, change the line above it to look like this:

		$_profile_cache['tpl_profile'] = '<a href="{PROFILE_URL}" onclick="ajaxbox_on();$.get(\'{PROFILE_URL}&ajax=y\',function(data){$(\'#msg-ajax\').html(data);set_ajaxbox();});return false">{USERNAME}</a>';

Assuming you have made the changes to memberlist_view.html that were outlined in my original post, this should get everything working when members click on profiles.
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
phpBB3 AJAX
Posted July 9th 2015, 6:04am
Thank you !! It`s working as it should. But how can I fix the white page when you are not logged in and click on profiles ? And I would need a (view full profile) button to appear in the pop-up window. Can somebody help me with that ? I don`t know php, no idea how to do that :( . Thank you for your support!.
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted July 11th 2015, 9:30am
Nobody ?? :(
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4
phpBB3 AJAX
Posted July 11th 2015, 3:33pm
You should find the part of the get_username_string() function that starts with function get_username_string( and ends with switch ($mode), and replace all of it with the following:

function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false)
{
global $user, $auth;
static $_profile_cache;

// We cache some common variables we need within this function
if (empty($_profile_cache))
{
global $phpbb_root_path, $phpEx;

$ajax = ($user->data['is_registered']) ? ' onclick="ajaxbox_on();$.get(\'{PROFILE_URL}&ajax=y\',function(data){$(\'#msg-ajax\').html(data);set_ajaxbox();});return false"' : '';

$_profile_cache['base_url'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u={USER_ID}');
$_profile_cache['tpl_noprofile'] = '{USERNAME}';
$_profile_cache['tpl_noprofile_colour'] = '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
$_profile_cache['tpl_profile'] = '<a href="{PROFILE_URL}"' . $ajax . '>{USERNAME}</a>';
$_profile_cache['tpl_profile_colour'] = '<a href="{PROFILE_URL}"' . $ajax . ' style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
}

// This switch makes sure we only run code required for the mode
switch ($mode)

This should fix the blank screen issue.
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
phpBB3 AJAX
Posted July 12th 2015, 1:42am
Perfect! Thank you very much! . Is there a way that we can put that window in a pop-up ?
φ
Posts: 22
Joined: May 2nd 2015, 4:29pm
Likes Given: 4

Who is online

Users browsing this forum: No registered users and 0 guests