Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Forms on dataobjects


Go to End


1253 Views

Avatar
cumquat

Community Member, 201 Posts

3 March 2013 at 10:38am

Edited: 03/03/2013 11:33am

Hi guys,

Ok i need a bit of help.

I have a data object called SEARCH this lists info about a search (supprise supprise) each SEARCH can have many MISPERS. I have a SEARCHPAGE that lists all the current searches when i select a link it takes me to the rendered page for showing me the SEARCH and the MISPER details. what i would like to do is add a link in the page that allows me to edit the MISPER detail i am looking at.This is where i seem to have confused myself and now cannot see the wood from the trees.
I don't have a huge amount of knowledge on the whole MVC type approach but what i would like to happen is that the dataobject MISPER has a form on it that i can call in the rendered searchpage so far i've got that working but when i try to save said form it doesn't work it doesn't seem to know where to send/process the data. I'm sure this is due to a lack of controller and i'm used to using forms on an actual defined Pages. So i need to work out how to process a form that is on a dataobject.
If i try and process the form on the rendered search page i'm not sure how to pass the correct ID for the MISPER bearing in mind there could be multiple MISPERS per search on that page.

Any help or pointers appreciated.

Mick

Search.php

class Search extends DataObject implements PermissionProvider  {
   
  	  
   	static $db = array(
   		'Name' => 'Varchar(50)',
		'IncidentNum' => 'int',
   		'CalloutDate' => 'SS_Datetime',
		'Area' => 'Varchar(250)',
		'Notes' => 'Text',
		'RVGridref' => 'Varchar(20)',
		'CurrentSearch' => 'Boolean',
		
   );
   
  
	static $has_many = array (
		'AuditTrails' => 'AuditTrail',
		'Locations' => 'Location',
		'Contacts' => 'Contact',
		'Mispers' => 'Misper'
		
	);

Misper.php
class Misper extends DataObject  {
   
   static $db = array(
   	'Name' => 'Varchar(50)',
	'Nickname' => 'Varchar(50)',
	'MispNum' => 'Varchar(5)',	
	//Description
	'Age' => 'Varchar(20)',
	'Race' => 'Varchar(50)',
	'Gender' =>  "Enum( array('Male','Female'),'Male')",
	'Height' => 'Varchar(10)',
	'Weight' => 'Varchar(50)',
	'Hair' => 'Varchar(75)',
	'FacialHair' => 'Varchar(50)',
	'DOB' =>  'Date',
	'Notes' => 'Text',
	'SearchedBefore' => 'Boolean',
	//Clothing
	'Shirt' => 'Varchar(50)',
	'Jumper' => 'Varchar(50)',
	'Jacket' => 'Varchar(50)',
	'Headwear' => 'Varchar(50)',
	'Trousers' => 'Varchar(50)',
	'Footwear' => 'Varchar(50)',
	'Gloves' => 'Varchar(50)',
	'Glasses' => 'Varchar(50)',
	'Description' => 'Text',
		
   );
   
   static $has_one = array (
		'Photo' => 'Image',
		'Search' => 'Search'
	);

function MisperClothing() {
	$fields = new FieldList(
	HiddenField::create('ID', 'aID', $this->ID),
	//HiddenField::create('MemberID', 'aID', $member),
					
	HeaderField::create('LocationHeader' ,  'Misper Clothing' , 3),
						
	TextField::create("Shirt","Shirt/Blouse"),
	TextField::create("Jumper", "Jumper"),
	TextField::create("Jacket"),
	TextField::create("Headwear"),	
	TextField::create("Trousers"),	
	TextField::create("Footwear"),	
	TextField::create("Gloves"),	
	TextField::create("Glasses")		
					
);
         
       	
	$actions = FieldList::create(
            FormAction::create("doMisperClothing","Update Mipser")
               		
				
		
	);
			
	$form = Form::create($this, 'MisperClothing', $fields,  $actions);
						
			
	$editmis = Misper::get()->filter('ID', $this->ID)->First();
		
	$form->loadDataFrom($editmis->data());
		
	return $form;
			
		
}
function doMisperClothing($data, $form){

	$theID = $_POST["ID"];
	$mis = Misper::get()->byID($theID);
	$form->saveInto($mis);
	$mis->write();
	Director::redirectBack();
		
		
}

TheSearch.ss

	<% with getSearch %>
	...
		<% loop Mispers %>
		...
	
		$MisperClothing
		...
		<% end_loop %>
	<% end_with %>