Professional Web Applications Themes

mail via html form advice req - PHP Development

Ok, i think this is a very simple task. I decided to do it in the following way: I have two files: "\somefolder\contact.htm" which containts the form and "\somefolder\sendmail.php" which contains the php code. The form POSTs the data to sendmail.php.In order to check whether there are POSTed data I have a hidden field (name it "hid"). The php script tests whether the hid value is set and if not it redirects user to contact.htm. Here is the idea: <?php if ($_POST['hid'] != 'laughoutloud') { // no data posted, lets go back to contact htm: header('Location: ????contact.htm'); } else { ...

  1. #1

    Default mail via html form advice req

    Ok, i think this is a very simple task. I decided to do it in the following
    way:

    I have two files: "\somefolder\contact.htm" which containts the form and
    "\somefolder\sendmail.php" which contains the php code. The form POSTs the
    data to sendmail.php.In order to check whether there are POSTed data I have
    a hidden field (name it "hid"). The php script tests whether the hid value
    is set and if not it redirects user to contact.htm. Here is the idea:

    <?php
    if ($_POST['hid'] != 'laughoutloud') {
    // no data posted, lets go back to contact htm:
    header('Location: ????contact.htm');
    }
    else {
    // ok lets send the mail
    if mail(stuff blah blah) ... print result and redirect after 5 secs
    }
    ?>

    My problem is this one: I don't want to use an absolute link in the
    redirection (so that if I move sendmail and contact to other folders they
    would still work). I only want to redirect to the file contact.htm placed on
    the same dir with sendmail.php.If I type:

    header('Location: contact.htm');

    then the redirection does not work (which is what I expected). If I type

    header('Location: http://blah stuff blah/somefolder/contact.htm');

    Then if I move the files to somefolder2, redirection will stop working.

    I could use 'PHP_SELF' and edit the string, but isn't there a better way to
    do this?


    Thank you for your time


    Nick Guest

  2. #2

    Default Re: mail via html form advice req

    "Nick Valeous" <com> wrote:
     

    Can I ask a stupid newbie question here: Why wouldn't you expect that to
    work? I don't believe redirections *have* to be absolute (unless you've
    defined a <base href> or something).

    --
    bonfils
    http://kim.bonfils.com


    bonfils Guest

  3. #3

    Default Re: mail via html form advice req



    Also, if you keep the two pages together, it shouldn't be a problem. The
    following is the standard stuff I stick in for a Guest Book in my sites.


    guest_book.php

    <table width=780 cellspacing=0 cellpadding=0 border=0><tr><td><br>

    <table width=500 align=center cellspacing=0 cellpadding=8 border=2
    bgcolor="#ffffee"><tr><td align=center>Please feel free to make an entry in
    our Guest Book - let us know what you think of the website, what you've
    learned of XYZ from it, etc, etc</td></tr></table>

    <form method=post action="guest_book_add_handle.php">
    <table width=580 align=center cellspacing=0 cellpadding=4 border=0>
    <tr><td>First name? - <br><input type=text name="firstname"
    size=12></td><td>Surname? - <br><input type=text
    name="surname"></td></tr><tr><td colspan=2>Your e-mail address? - (this will
    <strong>not</strong> be made public)<br><input type=text name="email"
    size=60></td></tr>
    <tr><td colspan=2>Your comments? - about our website? - about XYZ? - about
    you?<br><textarea name="entry" cols=55 rows=8></textarea></td></tr>
    <tr><td colspan=2 align=right><input type=submit name="submit"
    value="Enter"> &nbsp; &nbsp; &nbsp; &nbsp; <input type=reset name="reset"
    value="Clear"> <br>
    </td></tr></table>
    </form>
    </td></tr></table>


    guest_book_add_handle.php

    <?
    if ((!$firstname) || (!$surname) || (!$email) || (!$entry))
    {
    header("location:guest_book.php");
    exit();
    }
    $date=date("jS F Y");
    mail("co.uk", "Guest book", "New
    contribution to the Guest Book - $date.");

    Stick the data into the database.
    ------------------------------------------------------------

    This post did not necessarily reflect my opinions. So there.
    Pull the pins out to reply direct.
    Fat Guest

  4. #4

    Default Re: mail via html form advice req

    bonfils wrote: 

    HTTP Location headers must contain an absolute URI. See
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30

    Admittedly, it seems some browsers can cope with relative URIs, but this
    by no means that you should rely on it.

    To the OP, go to http://www.php.net/header. The 5th example down shows
    you how to deal with this problem.

    --
    Oli
    Oli Guest

  5. #5

    Default Re: mail via html form advice req

    my answer is here: http://www.tipsntutorials.com/tips/PHP/23

    basename($PHP_SELF);

    simple as that:-)

    "Nick Valeous" <com> wrote in message
    news:cv5j0i$6fj$otenet.gr... 
    following 
    have 
    secs 
    on 
    to 


    Nick Guest

Similar Threads

  1. form advice needed
    By pflynn02 in forum Macromedia ColdFusion
    Replies: 18
    Last Post: May 8th, 12:19 AM
  2. WEB FORM SUBMIT BY E-MAIL OR ATTACH FORM TO E-MAIL
    By GetGoing in forum Web Design
    Replies: 3
    Last Post: October 28th, 02:17 PM
  3. Mail:Sender - HTML Mail with alternatives problem
    By Bjoern Raue in forum PERL Modules
    Replies: 2
    Last Post: July 26th, 08:52 AM
  4. need some form advice
    By Phil in forum Macromedia Dreamweaver
    Replies: 2
    Last Post: July 31st, 06:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139