Wow finally got this working, thanks UncleCheese! :D
yes that getCMSActions works perfectly, and had I not got the other way working I would probably use that, the only thing is it's a bit close to the save and publish button and as the EndSeason function deletes all the fixtures from the current season and is only going to be used once a year I would rather hide it away in another tab.
so in order to get it to pass the ID in the iframe URL i had to create a new SeasonField.php class which returned the iframe HTML just like the other iframe fields. I copied the code from the ImageField.php as you suggested and made it an extention of FormField instead of FileField and got it to return the correct URl as for some reason if i put {$this->ID} into the LiteralField call it just passed the literal URL of 'EndSeasonController/iframe/{$this->ID}'.
Anyway both methods work. Thanks again, this was a real tough one for me and I wouldnt have managed it without your help :)
below is my code for anyone that is interested:
mysite/code/TeamPage.php
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Seasons', new SeasonField('EndSeason', 'Finsih the current Season'), 'Content');
return $fields;
}
mysite/code/SeasonField.php
class SeasonField extends FormField {
public function Field($id = null) {
$data = $this->form->getRecord();
if($id && is_numeric($id)) {
$parentID = $id;
} elseif($data) {
$parentID = $data->ID;
} else {
$parentID = null;
}
$iframe = "<iframe name=\"{$this->name}_iframe\" src=\"EndSeasonController/iframe/$parentID/\" style=\"height: 82px; width: 425px; border: none;\" frameborder=\"0\"></iframe>";
return $iframe;
}
}
mysite/code/EndSeasoncontroller.php
class EndSeasonController extends Controller
{
static $allowed_actions = array ('iframe');
function EndSeasonForm()
{
$params = Director::urlParams();
return new Form(
$this,
"EndSeasonForm",
new FieldSet( new HiddenField('ID', 'Page ID',$params['ID'])),
new FieldSet( new FormAction('EndSeason', 'End the Season'))
);
}
function Link(){
}
function EndSeason($data, $form){
//My end season procedure
}
}
themes/mySite/templates/EndSeasonController_iframe.ss
<!DOCTYPE [insert full doctype]>
<body>
$EndSeasonForm
</body>
</html>