Filling out Web Form from Script

I am trying to fill out a web form from within a script I am writing. I think that I should be using curl to do this, but I'm not really sure. The form has username and password fields and a submit button. I want to be able to log in from the command line.

Html from the site:

<h5 align="center"><font color="#000000"><div align="center">
    <table class = "singleTable" width="400" height="275" id="table1">
        <tr>
            <td>
                <form action="https://safeconnect.bucknell.edu:8443/authenticate.!^" name="loginForm" method="post" onsubmit="return validateForm(this)" >
                      <table width="100%" id="table2">
                        <tr>
                            <td colspan="2">�</td>
                        </tr>
                        <tr>
                            <td>
                                <p align="right"><label for="username">Network Username:</label></td>
                            <td> 
                              <input type="text" name="userId" id="    " tabindex="1" accesskey="u" value="" size="16" /></td>
                        </tr>
                        <tr>
                            <td>
                                <p align="right">Password:</td>
                            <td>
                              <input type="password" name="pass" id="password" tabindex="2" accesskey="p" value="" size="16" /></td>
                        </tr>
                        <tr>
                            
                        </tr>
                        <tr>
                            <td colspan="2">
                            <p align="center">
                            <div style="display: none;" id="autherror">
                                    <h5 align="center"><font color="#000000">Please enter valid credentials</font></h5>
                                </div>
                            <p align="center">
                            <input type="submit" tabindex="3" accesskey="l" value="Submit" /></td>
                        </tr>
                        
                    </table>
                    
                </form>
            </td>
        </tr>
    </table>
</div></font></h5>
</div>

Any help would be greatly appreciated.

You can get a script from the curl website called formfind. You download the html page or just save your post to an html file, then run formfind on it (./formfind < index.html). You will get some output like:

 --- FORM report. Uses POST to URL "https://safeconnect.bucknell.edu:8443/authenticate.!^"
Input: NAME="userId" (TEXT)
Input: NAME="pass" (PASSWORD)
Button: "Submit" (SUBMIT)
--- end of FORM

That tells you the things you need to input, what they're called, and what url the data actually gets sent to.

You then use curl with those values:
curl -d "userId=YOURNAME&pass=YOURPASS" 'https://safeconnect.bucknell.edu:8443/authenticate.!^'

or

curl -d userId=YOURNAME -d pass=YOURPASS" 'https://safeconnect.bucknell.edu:8443/authenticate.!^'

I only single quoted the url because of the "!^" at the end. Quotes aren't normally needed. Sometimes you may need to use "curl -k" and sometimes the -d needs to be -F. I haven't read up on it, but I have 3 systems, and all three need a different curl command for the same site.

Thanks. That was just what I was looking for. It works perfectly.