Pet biographies!

Forum
Last Post
Threads / Messages

Dinocanid

Member
Member
Joined
Aug 30, 2016
Messages
520
Points
18
Age
23
Location
Maryland, USA
Mysidian Dollar
43,334
This tutorial allows you to add biographies to your adopts. Let me know if you get any errors since I worked on this on and off and I might have forgotten to include a line of code somewhere.

Setup
This is the stuff you need to do in phpMyAdmin before you go edit anything else. I'm sure this tutorial won't work otherwise.
Find adopts_owned_adoptables and add 1 column under the structure tab with this info:
  Spoiler: What to add 
Name: petbio
Type: VARCHAR
Length/Values: 500
Default: NULL
Collation: latin1_swedish_ci
Check the box that says null

You can change the length to whatever you want the max number of characters allowed in an adoptable's bio to be. I put 500 since that seems reasonable.

Foundation
Now for the bulk of this tutorial: Editing. This part is for getting the under-the-hood stuff for the bio working so it actually saves after you type it. Let's work from the outside in.

Step 1
Go to myadopts.php and add this to it:
PHP:
public function changepetbio(){
		$mysidia = Registry::get("mysidia");		
		if($mysidia->input->post("submit")){
		    $poundsettings = getpoundsettings();
		    $poundpet = $mysidia->db->select("pounds", array(), "aid='{$this->adopt->getAdoptID()}'")->fetchObject();
			if($poundpet and $poundsettings->rename->active == "yes"){
			    if(!empty($poundpet->firstowner) and $mysidia->user->username != $poundpet->firstowner){
				    $this->setFlags("rename_error", "rename_owner");
                    return;	
                }				
            }			
			$this->adopt->setPetbio($mysidia->input->post("petbio"), "update");
		}
        $this->setField("adopt", $this->adopt);		
	$this->setField("image", $this->image);			
	}
As you can probably see, I basically duplicated the rename function. Some of it can probably be cleaned up if you know how, but I don't.

Step 2
Go to classes>class_ownedadoptable.php and add this with all the other protected and public stuff (All that yellow stuff between "class OwnedAdoptable" and "public function_construct")
PHP:
public $petbio;
Once you do that, add these lines with all the other functions. It can be towards the bottom or something.
PHP:
public function getPetbio(){
        return $this->petbio;
    }
    public function setPetbio($petbio, $assignMode = ""){
		if($assignMode == Model::UPDATE) $this->save("petbio", $petbio);
	    $this->petbio = $petbio;
	}

Step 3
Go to lang>lang_myadopts.php and add these lines:
PHP:
$lang['changebio'] = "Change the bio of ";
$lang['changebio_default'] = "This page allows you to change the bio of ";
$lang['changebio_details'] = ". To change this adoptable's bio, simply type it in the box below.";
$lang['changebio_error'] = "Cannot change";
$lang['changebio_owner'] = "The site admin has specified that only original owners can change their adoptables' bios.";  
$lang['changebio_success_title'] = "Bio Change Successful";
$lang['changebio_success'] = "You have successfully changed the bio of ";

Displaying and Using
We're halfway there, wow! This part is for adding the text areas, buttons, and links that will allow users to actually add bios to their adoptables; as well as displaying it on the adoptable's profile.

Step 1
Go to view>myadoptsview. After we're done, you can use the following line to display the bio wherever you want on a pet's profile. You can go ahead and add it now if you want so you can see it right after we finish.
PHP:
$bio = stripslashes($adopt->getPetbio()); 
Bio: {$bio}
You can also use this if your profile code is structured differently from mine:
PHP:
$bio = stripslashes($adopt->getPetbio()); 
$document->add(new Comment(Bio: {$bio}));

Step 2
Add this code with all the other functions. You can put it towards the bottom to keep things organized:
PHP:
public function changepetbio(){
		$mysidia = Registry::get("mysidia");
		$adopt = $this->getField("adopt");		
		$image = $this->getField("image");		
		$document = $this->document;
		
		if($mysidia->input->post("submit")){
			$document->setTitle($this->lang->changebio_success_title);
			$document->add($image);
			$message = "<br>{$this->lang->changebio_success}{$adopt->getName()}. 
					    You can now manage {$mysidia->input->post("adoptname")} on the";
			$document->addLangvar($message);
			$document->add(new Link("myadopts/manage/{$adopt->getAdoptID()}", "My Adopts Page"));
			return;
		}
		
		$document->setTitle($this->lang->changebio.$adopt->getName());
		$document->add($image);
		$document->addLangvar("<br />{$this->lang->changebio_default}{$adopt->getName()}{$this->lang->changebio_details}<br />");
		
		$petbioForm = new FormBuilder("petbioform", "", "post");
		$petbioForm->buildTextArea("petbio")->buildButton("Change Bio", "submit", "submit");
		$document->add($petbioForm);		   
	}
Another rename replica :veeee:. This huge chunk basically works like the rename function and takes the user to a page that lets them edit the bio.

Step 3
Done? Good, now just scroll back up and add this with all the other links on your adoptable's profile. (Along with rename, trade status, freeze, etc.)
PHP:
$document->add(new Link("myadopts/changepetbio/{$aid}", " Change {$name}'s Bio", TRUE));

The End
Aaand...you're done! To test this, go to your pet's profile and click on the new link we added. This should take you to a screen where you can type in whatever you want for the bio. Once you hit the "Change Bio" button, it takes you back to the profile with your pet's new and shiny biography.
 
Last edited:
I'm receiving the following error: Database error 1054 - Unknown column 'petbio' in 'field list'

This is after I click on update for the pet's bio.

How can I fix this?
 
I'll try to redo all of the steps. Maybe I just missed something and don't know it.
 
I just tried it and it works for me. I noticed it has a "/" in words like "I've" and "pet's".
 
Mysidia has a problem with apostrophes in text, so it will add backslashes wherever they're used. The only way to get rid of them is to go to the bio in phpMyAdmin and manually remove the \'s, or avoid using apostrophes. I wish there was a way to prevent it though, they pop up everywhere on my site since I use them a lot :/
 
Ah, so it's just me then. I'll redo the steps as soon as I fix the inventory issue I have going on. :eye:
 
Dinocanid, you can use a stripslashes command to remove backslashes but I'm not too sure where you'd place them in yours XD I'm gonna have a go though, and will share if I get it..

EDIT: Done!

This isn't too elegant.. and I have sooo many places to put it >.> But it works!

Where you have your profile (bio, I suppose) placed you need to include this somewhere:

$bio = stripslashes($adopt->getPetbio());

That's what I have on my 'manage adopt' page, and it works! (I am using Kyttias' profile page method of displaying stuff so that might make it work? I'm not sure.)

Basically place that where you have biographies displayed :)

Oh, and remember to put {$bio} (or just $bio) instead of the full string, to those who might be confused :)
 
Last edited:
if you change the $petbioForm->buildTextArea with

PHP:
        $petbioForm->buildTextArea("petbio",$bio)->buildButton("Change Bio", "submit", "submit");

the current bio will be displayed in the text box that way if the user want to edit instead of rewriting the full bio
for this code to work you must also add the stripslashes code posted by parayna =)

in the end it must look like this:
PHP:
        $bio = stripslashes($adopt->getPetbio()); 
        $petbioForm = new FormBuilder("petbioform", "", "post");
        $petbioForm->buildTextArea("petbio",$bio)->buildButton("Change Bio", "submit", "submit");
        $document->add($petbioForm);
in case i dint explain well ^^
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,120
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top