I have a form
in my Visualforce
page with an inputFile
tag. If the user clicks the submit button
without choosing a file i want to display an error message and force him to choose a file from his computer. and if he choose a file the action will be processed and he will be redirected to another Visualforce
page.
This the code of my visualforce
page:
<apex:form id="myForm" >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Send" action="{!processForm}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Form Data" columns="1">
<apex:inputText label="Name" value="{!name}"/>
<apex:inputText label="Comment" value="{!myComment}"/>
<apex:inputFile value="{!myFile}" fileName="{!fileName}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
an this is the Apex
code that process the form
:
public PageReference processForm() {
String theFile = myFile.toString();
// here i process the data of my form
// and here i redirect to a new page
PageReference newPage = new PageReference(url to my page);
newPage.setRedirect(true);
return newPage;
}