Web form: Frustrating problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davidiwharper
    New Member
    • Mar 2007
    • 20

    Web form: Frustrating problem

    Hi everyone,

    I'm writing a web form and a backend Perl script to send a query to the administrator.

    V1 of the script is working well, it's basically just a simple get-data-send-email [sendmail] script. V2, on the other hand, is a nightmare. I added just a few changes.

    In the HTML page (which has become an SHTML page to support a server includes:

    Code:
    <form method="post" onsubmit="return checkform()" action="/cgi-bin/activate_v2.pl" >
    
    <input type="hidden" id="ip" value="127.0.0.1" />
    In the Javascript:

    Code:
    /* New code: Gets IP address using SSI */
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    
    /* New code: Adds IP address to hidden field */
    document.getElementById("ip").value = ip;
    In the Perl:

    Code:
    my $ip = "127.0.0.1";
    
    $ip = param('ip');
    
    # now we can check the data
    
    if ($fullname eq "" || $address eq "" || $username eq "" || $sender eq "") {
    		
    	# we have incomplete data, so we will serve an error
    
    	# set the web page parameters
    
    	$content_header = 'Incomplete Information';
    	$content = '<p>Your activation request not been submitted.</p> <p>You did not fill out all of the requested information on the previous page. Please return to the main activation page and complete the form as directed.</p> <p>If you feel that you received this message in error, please <a href="mailto:admin@our-website.com">email the web services administrator</a>.</p>';
    	$site_url = '/activate/';
    	$link = 'Click here to return to the previous page';
    
    	# $activate = 0;  # not needed as this parameter was set at the beginning
    
    }
    
    else {
    
    	# everything is okay
    	$activate = 1;
    
    if ($activate == 1) {
    
    	# it's okay to submit the request
    I'm completely lost (as evidenced by my previous, late unlamented post...).

    I should mention that I have tried changing the POST method to GET to try and see what is passed to the script, but nothing seems to be being passed over.

    Also, I originally broke the code up into subroutines, but when the program didn't work I lumped it all back together again for troubleshooting purposes.

    Perhaps I should break this problem into two and try to run the Perl script from the shell? How can I pass parameters to the script (i.e. "ip", "fullname" etc.)?
  • davidiwharper
    New Member
    • Mar 2007
    • 20

    #2
    I should mention the actual problem I guess: I always get the error page, not the success page. When I've tried printing the variables (ip, fullname etc) collected at the beginning of the script to the screen (the HTML page), they display as blank.

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      one of these conditions is true so your script does the error stuff:

      Code:
      if ($fullname eq "" || $address eq "" || $username eq "" || $sender eq "") {
      but there is no way to tell by looking at the code or from anything you said to know why that is. Are the above variables getting defined somewhere? Print them out to the screen to see what their values are.

      Comment

      • davidiwharper
        New Member
        • Mar 2007
        • 20

        #4
        Indeed, unfortunately all of them are true. The problem is I don't know why.

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          The obvious question is: where are these variables being defined?

          Code:
          if ($fullname eq "" || $address eq "" || $username eq "" || $sender eq "") {
          are they data from a form? Where is the data from the form getting put into those variables?

          Comment

          • davidiwharper
            New Member
            • Mar 2007
            • 20

            #6
            On the form:

            Code:
            <form method="post" onsubmit="return checkform()" action="/cgi-bin/activate_v2.pl" >
            
            <input type="hidden" id="ip" value="127.0.0.1" />
            
            <p><table>
            <tr>
            	<td>Full Name:</td>
            	<td><input type="text" id="fullname" size="31" /></td>
            </tr>
            <tr>
            	<td>Street Address:</td>
            	<td><input type="text" id="address" size="31" /></td>
            </tr>
            <tr>
            	<td>Email Address:</td>
            	<td><input type="text" id="email" size="31" /></td>
            </tr>
            <tr>
            	<td>Website User Name: </td>
            	<td><input type="text" id="username" size="31" /></td>
            </tr>
            </table></p>
            			
            <p><button type="submit">Submit</button></p>
            
            </form>
            There's also a smigden of Javascript to alter the 'ip' hidden field, which I have noted in my first post.

            From the Perl script:

            Code:
            my $sender = 'noreply@our-website.com';
            my $fullname = '';
            my $address = '';
            my $username = '';
            my $ip = "127.0.0.1";
            
            ### some other stuff, not posted ###
            
            # gets data from the initial HTML form
            
            # get all of the form contents
            
            my $formcontents = "";
            
            foreach my $field (param) {
            
            	foreach my $value (param($field)) {
            
            		$formcontents.= "$field: $value\n";
            
            	}
            }
            
            # now let's get the values from the form
            
            $fullname = param('fullname');
            
            $address = param('address');
            
            $sender = param('email');  # no need for a my statement
            
            $username = param('username');
            
            $ip = param('ip');

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              hard to tell, it's like trying to diagnose a patient when all you can see is an arm or a leg. Assuming your script has loaded the CGI module and the form fields are filled in, I can't see why the script doesn't seem to work right.

              Comment

              • davidiwharper
                New Member
                • Mar 2007
                • 20

                #8
                The problem is almost certainly in the changes I quoted at the beginning, V1 has none of these issues.

                But for the life of me I am stuck, and my teacher is as well. Looks like the script needs to be scrapped and I will have to do without the server-side error checks.

                Thanks.
                David

                Comment

                • KevinADC
                  Recognized Expert Specialist
                  • Jan 2007
                  • 4092

                  #9
                  Try removing this part of the code

                  Code:
                  foreach my $field (param) {
                  
                  	foreach my $value (param($field)) {
                  
                  		$formcontents.= "$field: $value\n";
                  
                  	}
                  }
                  it might be emptying the buffer so subsequent attempts to get data out of param() might be empty.

                  Comment

                  • davidiwharper
                    New Member
                    • Mar 2007
                    • 20

                    #10
                    Sorry about the delay in posting -- exams.

                    Great idea, but this didn't work. Thanks for the suggestion, any more? (hoping against hope here)

                    If you're ever in Australia look me up and I'll buy you a beer, heh... you deserve it, mate :-)

                    Comment

                    • KevinADC
                      Recognized Expert Specialist
                      • Jan 2007
                      • 4092

                      #11
                      print $formcontents out to a file or the screen and report back what it's value is.


                      Code:
                      foreach my $field (param) {
                      
                      	foreach my $value (param($field)) {
                      
                      		$formcontents.= "$field: $value\n";
                      
                      	}
                      }

                      Comment

                      • davidiwharper
                        New Member
                        • Mar 2007
                        • 20

                        #12
                        $formcontents is blank:

                        Form Contents:
                        There is literally no content, specifically no undef message. Just before the code you quoted, I defined $formcontents as "".

                        Thank you for your continued help with this.

                        David
                        Last edited by davidiwharper; Apr 6 '07, 03:58 AM. Reason: more claring

                        Comment

                        Working...