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

Form with SS_HTTPRequest could not be converted to string


Go to End


722 Views

Avatar
Dobby

Community Member, 15 Posts

23 September 2016 at 12:32am

I have a form that would work if i wouldn't have da Dataobject in it.

public function AntwortForm($ID) {
			

        $Nummer=Vortest_Fragen::get()->byID($ID);
		if ($Nummer) { $Art=$Nummer->Art;}
		if ($Art == "Normal"){
        $fields = new FieldList(
            TextAreaField::create('Antwort'),
            HiddenField::create('ID','ID',$ID),
            HiddenField::create('VortestID','VortestID',$this->request->param("ID")),
            HiddenField::create('Aktion','Aktion',$this->request->param("Action"))
			
        );
		} else {
			$Optionen = explode(";",$Nummer->Optionen);
			$a = "A";
	
			for ( $i=0 ; $i<count ($Optionen); $i++) {
			$Op[$a] ='<div style="width:25px;display:inline;">'.$a.')</div> '.$Optionen[$i];
			
				$a++;
			}  
			
			
			$fields = new FieldList(
            CheckboxSetField::create('Antwort',"Antwort",$Op),
            HiddenField::create('ID','ID',$ID),
            HiddenField::create('VortestID','VortestID',$this->request->param("ID")),
            HiddenField::create('Aktion','Aktion',$this->request->param("Action")),
            HiddenField::create('Art','Art',$Nummer->Art)
			
        );
		}
        $actions = new FieldList(
            FormAction::create('AntwortEintragen', 'Eintragen')
        );

        $form = new Form($this, 'AntwortForm', $fields, $actions);
        return $form;
    }	
	function AntwortEintragen($data, $form)  {

		   //Aktion für Schaltfläche, Formulardaten in DB speichern
		   //existiert der Satz schon?
		   $Antwort = Vortest_Antwort::get()->filter(array('FrageID' => $data['ID'], 'SchreiberID' => Member::currentUserID()));
		   //wenn nicht: neu anlegen
		   foreach($Antwort as $item) { 
			    $item->delete();
			}
		   
		   foreach ($data['Antwort'] as $Antwort) {
			   $Ant.=$Antwort.','; 
			   }
			$Antwort = new Vortest_Antwort();

			
		   // und immer speichern	
		   if ($data['Antwort']) {	
		   $form->saveInto($Antwort); 
		   if ($data['Art']=="Mechanics") {
		   	$Antwort->Antwort = $Ant;
		   } 
		   $Antwort->SchreiberID=Member::currentUserID();
		   $Antwort->FrageID=$data['ID'];
		   $Antwort->write();
		   }
		   $VID=$data['VortestID'];
		   // und zurück auf die Erfassungsseite mit leerem Formular
		if ($data['Aktion']=="AlleFragen") {
			$this->redirect('/vortest/AlleFragen/'.$VID.'#'.$data['FrageNr']);
		} elseif ($data['Aktion']=="Einzelfrage") {
			$this->redirect('/vortest/Einzelfrage/'.$VID);
		} else {
		   $this->redirect('/vortest/Test/'.$VID.'#'.$data['FrageNr']);
		 }
        }

It works when I change the $ID to a number in this line $Nummer=Vortest_Fragen::get()->byID($ID);
When I don't change it I get this message.
[Recoverable Error] Object of class SS_HTTPRequest could not be converted to string

What can I do?