function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sviatlana AndryianchykSviatlana Andryianchyk 

Form inputs are not passed within repeatable forms

Hi,
I am trying to pass variable value from visualforce page to my custom controller. But it is constantly null.
This is my page:
 
<apex:page id="productCatalog" controller="ItemController">
<table class="table" id="block">
   <apex:repeat value="{! items[key]}" var="item">
       <tr>
          <td class="col-md-2"></td><apex:outputText value="{! item.Name}"/>
          <td class="col-md-2">
             <apex:form >
                 <apex:pageblock >
                     <apex:inputText value="{!myinput}"/>
                     <apex:commandButton value="Submit" reRender="outputID" action="{!MyMethode}"/>
                 </apex:pageblock>
             </apex:form>
          </td>
       </tr>
    </apex:repeat>
</table>
</apex:page>
And tis is my controller:
public with sharing class ItemController {
 public string myInput{get;set;}

    public void MyMethode(){
        System.debug(myInput);
}
When I place form element out of the repeat block, everything works ok. But now the value of myInput is constantly null. Thank yoy in advance!


 
NagendraNagendra (Salesforce Developers) 
Hi Andry,

You are using <apex:form> <apex:inputText value="{!myinput}"/> in <apex:repeat> tag.
At the time of submit, controller does not know which instance of 'myinput' and from which Form you are referring to. My suggestion is to take the 'myinput' variable out of repeat tag. You can check with below code the value is coming perfect fine -
<apex:page id="productCatalog" controller="ItemController">
    <apex:form >
        <apex:repeat value="{!items}" var="item">
            <table class="table" id="block">
                <tr>
                    <td class="col-md-2"></td><apex:outputText value="{! item.Name}"/>
                </tr>
            </table>
        </apex:repeat>

        <apex:pageblock >
            <apex:inputText value="{!myinput}"/>
            <apex:commandButton value="Submit" reRender="outputID" action="{!MyMethode}"/>
        </apex:pageblock>
    </apex:form>
</apex:page>
If you really want to use <apex:form > <apex:inputText value="{!myinput}"/> in <apex:repeat> tag. We can write something like below using apexFunction, HTML input, JS
<apex:page id="productCatalog" controller="ItemController">
    <table class="table" id="block">
       <apex:repeat value="{!items[key]}" var="item">
           <tr>
              <td class="col-md-2"></td><apex:outputText value="{! item.Name}"/>
              <td class="col-md-2">
                 <apex:form >
                     <apex:pageblock >
                         <apex:inputText value="{!myinput}"/>
                         <input type="button" value="Submit" onclick="MyMethodeApexFunction(this.previousElementSibling.value);"/>
                     </apex:pageblock>
                 </apex:form>
              </td>
           </tr>
        </apex:repeat>
    </table>
    <apex:form>
        <apex:actionFunction name="MyMethodeApexFunction" action="{!MyMethode}" reRender="outputID">
            <apex:param name="tempparamater" value="" assignTo="{!myinput}"/>
        </apex:actionFunction>
    </apex:form>
</apex:page>
Please follow above code which might help.

Mark it as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering similar issue.

Thanks,
Nagendra.