The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

[Slightly difficult question] how to modify theme without page refresh

View previous topic View next topic Go down

Solved [Slightly difficult question] how to modify theme without page refresh

Post by developer.ryan on September 1st 2015, 2:07 pm

Hi everyone

I have a question a little difficult

How to modify the title of the topic without refresh page
any that i edit the title in the same subject without departing from the same page


Last edited by developer.ryan on September 2nd 2015, 7:49 pm; edited 1 time in total

developer.ryan
Forumember

Posts : 98
Reputation : 6
Language : English,Chinese,Italian,French
Location : The doors of development

http://javascript:self.close()

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by Ange Tuteur on September 1st 2015, 2:32 pm

To do anything like that, you'd need to utilize AJAX. This is an example of how you could update the content of a post :
Code:
$.post('/post', {
  subject : 'Topic title',
  message : 'Message content',
  mode : 'editpost',
  p : 'post_id',
  post : 1
});

You'd need to replace post_id with a valid post identifier. ( e.g. 1, 2, 3.. ) Furthermore, for this example to work you'd need to disable the security option "disallow unofficial forms to post on the forum" via General > Security.

If you want to get past that you need to first send a GET request to return the form data. For example :
Code:
$.get('/post?mode=editpost&p=1', function(data) {
  var form = $('form[name="post"]', data).serialize(); // get the serialized form data
  console.log(form); // view data in the console
});

You can then proceed to manipulate the data as needed and then submit a POST request to update the data.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by developer.ryan on September 1st 2015, 8:01 pm

Thank you, but nothing happens

In my profile I can modify date of birth

Example



i want same this

developer.ryan
Forumember

Posts : 98
Reputation : 6
Language : English,Chinese,Italian,French
Location : The doors of development

http://javascript:self.close()

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by Ange Tuteur on September 1st 2015, 8:17 pm

I'll need more information before I can do anything. Such as the URL of your forum, that way I have an understanding of the document.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by developer.ryan on September 1st 2015, 11:56 pm


developer.ryan
Forumember

Posts : 98
Reputation : 6
Language : English,Chinese,Italian,French
Location : The doors of development

http://javascript:self.close()

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by Ange Tuteur on September 2nd 2015, 12:27 pm

Thanks, version phpbb3 will be easy to work with.

Go to Modules > JavaScript codes management and Create a new script with the following settings.

Placement : In the topics
Code:
$(function() {
  var h2 = $('h2.topic-title')[0],
      a = document.createElement('A');

  // edit button attributes
  a.innerHTML = '&nbsp;<img src="http://i21.servimg.com/u/f21/18/21/60/73/10053510.png" alt="Edit Title"/>';
  a.title = 'Edit topic title';
  a.className = 'editTitle';
  a.href = '#';

  // edit function
  a.onclick = function(e) {
    var t = this;
    e.preventDefault();
   
    $.get('/post?mode=editpost&p=' + t.previousSibling.href.replace(/.*?#(\d+)/, '$1'), function(d) {
      var form = $('form[name="post"]', d)[0],
          newTitle = prompt('Please insert a new title for this topic.', form.subject.value);

      if (newTitle) {
        form.subject.value = newTitle;

        $.post('/post', $(form).serialize() + '&post=1', function(data) {
          $('h2.topic-title a[href^="/t"]').text(newTitle);
        });
      }
    });
  };

  if (h2 && /mode=editpost/.test(h2.previousSibling.innerHTML)) h2.appendChild(a);
  'par ange tuteur';
});

That will add a edit button next to the topic title of the first post. So it works correctly on all pages of a topic I'd recommend enabling the following option.

General > Messages > Config > Always show the first post in the topics : Yes

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by developer.ryan on September 2nd 2015, 7:48 pm

Wow this is awesome king

it works for me without any problem

Thank you very much. :rose:

developer.ryan
Forumember

Posts : 98
Reputation : 6
Language : English,Chinese,Italian,French
Location : The doors of development

http://javascript:self.close()

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by SLGray on September 2nd 2015, 8:47 pm

Topic solved and archived


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 36663
Reputation : 2445
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum