+ Start a Discussion

Simple Login Page - Please help.



I am very new here, i am doing a POC to show our data inside the salesforce website.


I will list out what all i have done.


1. I created a new app.

2. I created a new tab and a visual source page.


Below is the code for my visual source page


<apex:page standardController="Account" controller="LoginController">
<apex:pageBlock title="Hello {!$User.FirstName}! Please login">
    <apex:Form >
                <td><apex:inputField id="userName" value="{!userName}"/></td>                
                <td><apex:inputfield id="passWord" value="{!password}"/></td>                
                <td align="right"><apex:commandButton value="Login" action="{!loginFn}"/></td>



This is my custom controller

public class LoginController {
    public String userName;
    public String password;
    public LoginController () {
    public void loginFn() {
        Http http       = new Http();
        HttpRequest req = new HttpRequest();

        try {        
            req.setEndpoint('http://documentcollaboration.elementfx.com/phpscript/login.php?username='+userName+' &password='+password);
            HttpResponse res = http.send(req);
        } catch (Exception e) {           


When i click on the Login Button, the LoginFn will be called(atleast thats what i hope so)...




The above link will return an XML like below



Based on the XML i want to display contents accordingly in my visualpage... if the status is success then i want to redirect to an another page, else i want to display an error message.


Please help me on how to do this... what should i do.. also is there any error in my apex code or visualforce page?


Thanks and Regards,



You can't use inputfield to capture the user id and password, as these need to be backed by sobject fields rather than controller properties.  You could use input text.  You'll also need public getters/setters for them.







  public String userName {get; set;}
  public String password {get; set;}





   <td><apex:inputText id="userName" value="{!userName}"/></td>                
   <td><apex:inputText id="passWord" value="{!password}"/></td>                








Hi Bob,


Thanks, i changed my visualforce page and class.


But please help me in my other question,


From the HTTP response, how do i manipulate my pages?


Should i create two different pages? for successfull login and unsuccessfull login and redirect to them? if so how can i redirect actually from the apex code?





if you are getting xml than you may parse xml using xml dom,than check value of  status as success or failure and may redirect


You can redirect to another page from an apex controller using page references.  Here's an example that assumes you've created a visualforce page called LoginSuccess:



public PageReference sendToSuccess()
   PageReference pr=Page.LoginSuccess;

   return pr;






Thanks bob


Say if i have a grid in my page. I want to call a php and fill the grid with the values that i get.


In my page i will have a button and some other data and also a grid at the bottom. In that button's action i will call a function in my apex class.


From the apex class, i will call the php.... and i will get the result in the http response.. But now how can i fill the grid with the http response? i can redirect to a new page, but how can i fill the grid with the response? the rest of the page should be the same, only the grid should change.


how can i do it. Thanks for your help.




In case anyone stumbles across this thread, this would be achieve in the following way:


(1) Back the grid by an apex list of values

(2) Create an apex:commandbutton with an action of the controller method that calls out to the PHP and rebuilds the list of values for the grid

(3) Specify a rerender attribute on the commandbutton that contains the id of the grid - this will cause the grid to be redrawn once the action method completes.