views:

194

answers:

1

Hi all, I am writing a small application in Classic ASP. I have a page which has a form, which posts to a second page. Included with the form's POST, are file uploads, hence the need for a POST method.

The second page though is NOT seeing ANY of the fields being sent by the first page. Calling either Request("param") or Request.Form("param") both just return empty string.

If i switch the method on my form from POST to GET (with NO other changes), then the values are properly picked up by the receiving page, of course then I cannot do the file uploads, which are a crucial part of this application.

In GET mode, the parameters are all put on the url as expected. In POST mode, I fired up FireBug, and examined the POST data of my request. The originating form IS sending all the values in the request (they show up in FireBug as expected), so the problem seems to be on the receiving page's end.

The form is being submitted via code, called from the button with the onclick="javascript:saveMinutes();"

My form and the saveMinutes() function are declared as follows:

<form id="frmMinutes" enctype="multipart/form-data" method="post" action="saveminutes.asp">
<table id="tblMinutes" style="width: 100%;">
    <tr>
        <td>
            <select id="selYear" name="year" size="13" onclick="javascript:setDatePickerRange(); checkForMinutes();">
                <%For lc = Year(Now) To getMinutesFirstYear() Step - 1%>
                    <option value="<%=lc%>" <%If lc = Year(Now) Then%>selected="selected"<%End If%>><%=lc%></option>
                <%Next%>
            </select>
        </td>
        <td>
            <select id="selMonth" name="month" size="13" onclick="javascript:setDatePickerRange(); checkForMinutes();">
                <%For lc = 1 To 12%>
                    <option value="<%=lc%>" <%If lc = Month(Now) Then%>selected="selected"<%End If%>"><%=MonthName(lc)%></option>
                <%Next%>
            </select>
        </td>
        <td style="width: 100%; padding-left: 20px;">
                <table id="enterMinutes" style="width: 100%">
                    <tr>
                        <th>Topic:</th>
                        <td><input id="topic" name="topic" type="text" maxlength="100" field="topic" /></td>
                    </tr>
                     <tr>
                        <th>Presenter:</th>
                        <td><input id="presenter" name="presenter" type="text" maxlength="100" field="presenter" /></td>
                    </tr>
                     <tr>
                        <th>Date:</th>
                        <td><input id="mtgdate" name="mtgdate" type="text" maxlength="10" class="datepick" field="mtgdate" readonly="readonly" /></td>
                    </tr>
                     <tr>
                        <th style="vertical-align: top;">Files:</th>
                        <td style="text-align: left;">
                            <input id="file0" name="file0" type="file" size="35" /><span class="redEmphasis" style="margin: 0px 10px 0px 10px;">(.doc or .docx)</span><input type="button" value="+" onclick="javascript:addFileUpload();" />
                        </td>
                    </tr>
                     <tr>
                        <th style="vertical-align: top;"></th>
                        <td style="text-align: left; padding: 10px 0px 10px 0px;">
                            <input type="button" style="width: 100%" value="update minutes" onclick="javascript:saveMinutes();" />
                        </td>
                    </tr>
               </table>
               <span id="warnexist" class="redEmphasis" style="display: none;">The selected month already has associated minutes (). doc files take precedence over docx.</span>
        </td>
    </tr>
</table>
</form>

saveMinutes():

function saveMinutes() {
    if($('form#frmMinutes input[type=text]').filter(function () { return $(this).val() == '' }).length > 0) {
        alert('Please enter all fields.');
        return;
    }

    if ($('form#frmMinutes input#file0').filter(function () { return !$(this).val().match(/.*\.docx?$/i) }).length > 0) {
        alert('First file must be doc or docx.');
        return;
    }

    $('form#frmMinutes input[type=file]').filter(function () { return $(this).val() == '' }).next().remove();
    $('form#frmMinutes input[type=file]').filter(function () { return $(this).val() == '' }).remove();

    removeDupeFiles();

    // reindex file inputs after removing emptys/dupes
    var fs = $('form#frmMinutes input[type=file]:gt(0)');
    for (lc = 1; lc <= fs.length;  lc++) {
        var fid = 'file' + new String(lc);
        $(fs[lc-1]).attr('id', fid).attr('name', fid);
    }

    $('form#frmMinutes')[0].submit();
}
+5  A: 

When your from is encoded as multipart, you can't get the POST values as plain old parameters. They are just additional parts of the multipart form.

To retrieve the uploaded files in ASP, you typically have to loop through the parts and check each one to see if it is a file (and then save it if it is). To get field values, you have to add to that loop to check each part to see if it has the name of one of your field values, and then retrieve the value. This is a pain to do in pure ASP code, so many people use some type of file upload component, in which case the retrieval of field values will depend on the component.

But the basic message is: whatever parsing of the form you're doing to retrieve the files, you have to do the same thing to retrieve the field values.

JacobM
That was it exactly; thanks!!!!!
eidylon