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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

getting form data from a form


Reply


7 Posts   1216 Views

Avatar
lozhowlett

Community Member, 146 Posts

1 November 2011 at 1:51am

Hi everyone

I cant seem to find the simple to answer to getting the actual form data submitted... I think this will show what I am trying to do...

function results($data, $form){

//echo $form;

Session::set('minprice', $data->$minprice);
Session::set('maxprice', $data->$minprice);
Session::set('minbeds', $data->$minprice);
Director::redirect("properties/");
}

basically i want to put into the session var the value of the form field submitted.... I cant find documentation on this anywhere!!

In asp i would do something like

MyVar = request.form("FieldName")

Any help would be great!

Thanks

Avatar
swaiba

Forum Moderator, 1804 Posts

1 November 2011 at 2:02am

firstly try

Debug::show($data);

to understand what is in the var, then maybe

$vars = $data->postVars();

will provide you data int eh expected $_POST format

Avatar
lozhowlett

Community Member, 146 Posts

1 November 2011 at 2:07am

thanks for that... however i get

Fatal error: Call to a member function postVars() on a non-object in /var/sites/t/test.jplettings.com/public_html/mysite/code/Page.php on line 61

Any ideas?

//Debug::show($data);
$vars = $data->postVars();
Debug::show($vars);
Session::set('minprice', $data->$minprice);
Session::set('maxprice', $data->$minprice);
Session::set('minbeds', $data->$minprice);
Director::redirect("properties/");

Avatar
swaiba

Forum Moderator, 1804 Posts

1 November 2011 at 2:09am

ok, what about the first debug show, doesn't that let you know the class name and data?

Avatar
lozhowlett

Community Member, 146 Posts

1 November 2011 at 2:10am

This is the data I get...

Debug (Page_Controller->results() in line 60 of Page.php)

url =
/property-holder/54-new-street/SearchForm
minprice =
0
maxprice =
0
minbeds =
1
action_results =

Avatar
swaiba

Forum Moderator, 1804 Posts

1 November 2011 at 2:16am

so have you tried $data['minprice']?

Avatar
lozhowlett

Community Member, 146 Posts

1 November 2011 at 2:18am

no - thats what I needed to know! Thank you :) is that standard PHP or SS specific? I am on a big learning curve! cheers