#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    5
    Rep Power
    0

    Possible to Redirect to a URL???


    Hi, I have this script that accepts data passed from a form, and im trying to redirect to a url after it processes the data and sends the email. Is this possible or any suggestions? ...this is the python code


    #!/usr/local/bin/python
    import cgi, os, re

    sendmail="/bin/sendmail -t"

    def print_header():
    print "Content-type: text/html"
    print
    print "<HTML>"
    print "<HEAD><TITLE>SEND MAIL FORM</TITLE></HEAD>"
    print "<BODY>"

    def disp_query (form):
    AllFieldsOk=1
    fields = form.keys()
    ##################################
    # Check all input field are full #
    ##################################
    if not 'FirstName' in fields : AllFieldsOk=0
    if not 'LastName' in fields : AllFieldsOk=0
    if not 'E-mail' in fields : AllFieldsOk=0
    else :
    if not "@" in form['E-mail'] :
    print "Bad E-mail address<BR>"
    AllFieldsOk=0
    if not 'Comments' in fields : AllFieldsOk=0

    if AllFieldsOk == 0 :
    print "One field or more in the form is empty<BR>"
    print "Go back to the previous page and fill all the fields"
    else:
    fp = os.popen(sendmail, "w")
    fp.write("To: %s\n" % form['DEST_EMAIL'])
    fp.write("from: %s\n" % form['E-mail'])
    fp.write("Subject: %s\n" % form['subject'])
    fp.write("%s\n" % form['Comments'])
    fp.write("First Name: %s\n" % form['FirstName'])
    fp.write("Last Name: %s\n\n" % form['LastName'])
    print "Message sent"

    def print_footer():
    print "</BODY></HTML>"

    def Main():
    form = cgi.SvFormContentDict()
    print_header()
    disp_query (form)
    print_footer()

    Main()
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    7
    Rep Power
    0
    Hi

    I used the following code for redirection:

    Code:
    print "Content-Type: text/html"
            print
            print "<html>"
            print "<meta http-equiv=refresh content=0;url=/myurl.html>"
            print "</html>"
    Hope this helps
    Oli
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Depending on how you set your Page up you can use the Location header to redirect a user, as long as no other data has been outputed already

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo