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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Show DB entry with ID what is given with a form..


Go to End


1611 Views

Avatar
SalvaStripe

Community Member, 89 Posts

18 February 2009 at 10:01pm

hey guys, i need help :D

when i create any form to many any stuff, i do this for example:

	function SpeicherSprache() {
		if(Member::currentUserID()) {
				$fieldset = new FieldSet(
					new TextField(
						$name = "Sprache",
						$title = "Sprache",
						$value = ""
					...
					...
					...
					...
					new TextField(
						$name = "Muttersprache",
						$title = "Muttersprache",
						$value = ""
					)
				);
				
			$actions = new FieldSet(
				new FormAction('doSenden', 'Submit')
			);
			
			return new Form($this, 'SpeicherSprache', $fieldset, $actions);
		} else
			return false;
	}

	function doSenden($data, $form) {
		$submission = new SprachenObjekt();
		$form->saveInto($submission);
		$submission->write();
		
		Director::redirectBack();
	}

and this works. "SprachenObjekt" is just a DataObjekt i created.

soo.. now the User should have an DropdownField to choose one ob the many "SprachenObjekt" in the DB.
hier code:

	function HoleSprache() {
		$myDoSet = DataObject::get("SprachenObjekt","");
		if($myDoSet){
			$map = $myDoSet->toDropDownMap('ID', 'Sprache');
			$map = str_replace($search = array('<', '>'), $replace = array('&lt;', '&gt;'), $map);
			
			$fieldset = new FieldSet(
				new DropdownField(
					$name = "sprachen",
					$title = "Sprache w&auml;hlen",
					$source = $map,
					$value = ""
				)
			);
		}

		$actions = new FieldSet(
			new FormAction('ZeigeSprache', 'Anzeigen')
		);
		
		return new Form($this, 'HoleSprache', $fieldset, $actions);
	}
	
	function ZeigeSprache() {
		if(!isset($_POST['sprachen']))
		$_POST['sprachen'] = 1;

		$sprache = new DataObjectSet();
		
		$result = DB::query("SELECT * FROM SprachenObjekt WHERE ID = '".$_POST['sprachen']."'");
				
		if($result) {
			foreach($result as $value) {
				$eintraege =  array(
									'ID' => $value['ID'],
									'Sprache' => $value['Sprache'],
									'Kaum' => $value['Kaum'],
									'Mittel' => $value['Mittel'],
									'Gut' => $value['Gut'],
									'Muttersprache' => $value['Muttersprache']
									);
				$sprache->push(new ArrayData($eintraege));
			}
		}
		return $sprache;
	}

And this code is in my .SS file:

        $HoleSprache
        
        <% control ZeigeSprache %>
              $Sprache<br />
              $Kaum<br />
              $Mittel<br />
              $Gut<br />
              $Muttersprache<br />
        <% end_control %>

Now when i enter into this page, the Data of DB entry with "ID = 1" is shown.
And there is the DropdownField and the Button.. BUT when i click the button i just get a white page with the word "DataObjektSet".
Okay, in other forms, there is a "RedirectBack()" in the called function.. so i dont know how to handle this problem.. :S

THANKS FOR ANSWERS