MODX Community

FormItIsSelected not saving to database table

The form I am developing is not saving the select options using FormItIsSelected.
The form is:

[[!FormIt?
&hooks=`formit2db,redirect`
&preHooks=`db2formit`
&autoPackage=`true`
&arrayFields=`["gender"]`
&prefix=`hon_`
&packagename=`honours`
&tablename=`membdetails`
&redirectto=`1`
&validate=`playername:required,
   gender:required`
 ]]

[[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]
<form action="[[~[[*id]]]]" method="post" class="memberForm">
<input name="resource_id" type="hidden" value="[[+fi.id]]" />
<div> 
<label for="playername">
    Player's name:
    <span class="error">[[!+fi.error.playername]]</span>
</label>
<input type="text" name="playername" id="playername" value="[[!+fi.playername]]" />
</div>
<div> 
</div>
<br class="clear" />
    <label>
        Gender:[[+fi.error.gender]]
        <select name="gender" value="[[!+fi.gender]]">
            <option value="">Select an option...</option>
            <option value="male"[[!+fi.gender:FormItIsSelected=`male`]] >Male</option>
            <option value="female"[[!+fi.gender:FormItIsSelected=`female`]] >Female</option>
        </select>
    </label>
<br class="clear" />
<input type="submit" value="Create Member" class="submitBtn" />
</form>
<p> </p>

Any suggestions would be appreciated.

Sorry all the form was not shown.

[[!FormIt?
&hooks=`formit2db,redirect`
&preHooks=`db2formit`
&autoPackage=`true`
&arrayFields=`["gender"]`
&prefix=`hon_`
&packagename=`honours`
&tablename=`membdetails`
&redirectto=`1`
&validate=`playername:required,
   gender:required`
 ]]

[[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]
<form action="[[~[[*id]]]]" method="post" class="memberForm">
<input name="resource_id" type="hidden" value="[[+fi.id]]" />
<div> 
<label for="playername">
    Player's name:
    <span class="error">[[!+fi.error.playername]]</span>
</label>
<input type="text" name="playername" id="playername" value="[[!+fi.playername]]" />
</div>
<div> 
</div>
<br class="clear" />
    <label>
        Gender:[[+fi.error.gender]]
        <select name="gender" value="[[!+fi.gender]]">
            <option value="">Select an option...</option>
            <option value="male"[[!+fi.gender:FormItIsSelected=`male`]] >Male</option>
            <option value="female"[[!+fi.gender:FormItIsSelected=`female`]] >Female</option>
        </select>
    </label>
<br class="clear" />
<input type="submit" value="Create Member" class="submitBtn" />
</form>
<p> </p>

The select part is

<label>
    Gender:[[+fi.error.gender]]
    <select name="gender" value="[[!+fi.gender]]">
        <option value="">Select an option...</option>
        <option value="male"[[!+fi.gender:FormItIsSelected=`male`]] >Male</option>
        <option value="female"[[!+fi.gender:FormItIsSelected=`female`]] >Female</option>
    </select>
</label>

Delete this line and it should work.

&arrayFields=["gender"]

You can delete the value attribute in the select-tag too.

<select name="gender">

Thanks halftrainedharry. It worked. It’s amazing the knowledge out there in the community.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.