How to retrieve form values in traditional way on VF without binding

Thursday, September 24, 2009 by Aslam - The Alexendra
For exmaple you have a form with below fields:-

<apex:form>
<input type="text" name="firstname"/>
<input type="text" name="lastname"/>
<apex:commandbutton value="SubmitMe" action="{!saveform}"/>
</apex:form>


Your apex class's saveform method:-

public PageReference saveform(){
string firstName = ApexPages.currentPage().getParameters().get('firstname');

string lastName = ApexPages.currentPage().getParameters().get('lastname');

//So simple
//Do your stuff


return null
}

Enjoy!!!
Posted in | 6 Comments »

6 comments:

Eric said...

That's awesome! I had no idea that worked.

Naresh said...

Thx for it:) I want to set current page's query string variable .. is there any set method like get method.. for controller's action ?

Aslam - The Alexendra said...

@Naresh: Yes, you can use...
ApexPages.currentPage().getParameters().put('name','testing');

Reena said...

You told me earlier too about this nice trick , It really helps.

Thanks

Venkata Narasimha Rao Vutla said...

This is very easy trick for retrieving the form elements. Very Useful Post!
Thanks bayya!

Haribabu Amudalapalli said...

wow great aslam.....thinking in new way.....

Post a Comment