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   1125 Views

Avatar
lozhowlett

1 November 2011 at 1:51am Community Member, 146 Posts

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

1 November 2011 at 2:02am Forum Moderator, 1796 Posts

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

1 November 2011 at 2:07am Community Member, 146 Posts

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

1 November 2011 at 2:09am Forum Moderator, 1796 Posts

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

Avatar
lozhowlett

1 November 2011 at 2:10am Community Member, 146 Posts

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

1 November 2011 at 2:16am Forum Moderator, 1796 Posts

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

Avatar
lozhowlett

1 November 2011 at 2:18am Community Member, 146 Posts

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