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 action causing SS_HTTPRequest error


Go to End


2 Posts   1895 Views

Avatar
zoose

Community Member, 4 Posts

15 April 2015 at 4:10pm

I have a simple form for editing simple objects. The form loads and populates as expected, but the action crashes out, referring to "[Notice] Object of class SS_HTTPRequest could not be converted to int"
In CalendarPage.php:

private static $allowed_actions = array(
		'view'
		, 'edit'
		, 'editForm'
		, 'doPostEdit'
		, 'doPostDelete'
	);
	
	public function edit($request) {
		if($entryRecord = DataList::create("CalendarEntry")->byID($this->request->param('ID'))) {
			return $this->customise(array(
				'Title' => 'Edit: ' . $entryRecord->Title
				, 'OneEntry' => $entryRecord
				, 'OneEntryForm' => self::editForm($entryRecord->ID)
			))->renderWith(array(
				'CalendarPage_actions'
				, 'CalendarPage'
				, 'Page'
			));
		} else {
			// Display a 404 page if user is not allowed this action or the source object cannot be found
			return ErrorPage::response_for(404);
		}
	}
public function editForm($rID) {
		$entry = DataList::create("CalendarEntry")->byID($rID);
		$fields = new FieldList();
			$nField = new HiddenField('ID', 'ID', $rID);
				$fields->push($nField);
			$tField = new TextField('Title', 'Title', $entry->Title);
				$fields->push($tField);
		$required = new RequiredFields('Title');
		$actions = new FieldList(
			new FormAction('doPostEdit', ' Save Changes ')
			, new FormAction('doPostDelete', ' Delete Event ')
		);
		$form = new Form($this, 'editForm', $fields, $actions, $required);
		return $form;
	}
	
	public function doPostEdit($data, $form, $request) {
		$entry = DataList::create("CalendarEntry")->byID($data['ID']);
		...
		$returnURL = $entry->getEventLink('view');
		return $this->redirect($returnURL);
	}

Everything works fine so long as I don't try to create an object in the action, then it all ends up in the cactus.
Oddest thing is, other forms almost identical work without issue. Baffled! Ideas?

Avatar
thomas.paulson

Community Member, 107 Posts

17 April 2015 at 8:48pm

Edited: 17/04/2015 8:51pm

I dont see any mistake, try update the code like mentioned below; might help

	public function edit(SS_HTTPRequest $request) {
		if($entryRecord = DataList::create("CalendarEntry")->byID($request->param('ID'))) {
			return $this->customise(array(
				'Title' => 'Edit: ' . $entryRecord->Title
				, 'OneEntry' => $entryRecord
				, 'OneEntryForm' => self::editForm($entryRecord->ID)
			))->renderWith(array(
				'CalendarPage_actions'
				, 'CalendarPage'
				, 'Page'
			));
		} else {
			// Display a 404 page if user is not allowed this action or the source object cannot be found
			return ErrorPage::response_for(404);
		}
	}