Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33

Thread: Mail form

  1. #1
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default Mail form

    Below you will see a .php mail form code. When I use a submit button in the contact.html, it all works fine. But when I use an image to submit, it doesn't work. It seems like something isn't correct in the .php.
    Can anyone adapt and make the script better, please ?

    Code:
    <?
    if ($_POST["Submit"]){
    
    if ($_POST["name"] and $_POST["email"] and $_POST["message"] ){
    
    mail (
    "info@casariegoart.com",
    "via website (EN)",
    "
    Name:     ".$_POST['name']."
    E-mail:   ".$_POST['email']."
    Message:  ".$_POST['message']."
    
    ",
    "From: ".$_POST['name']." <".$_POST['email'].">");
    
    echo '<p align="center"><font color="#003366">Thanks !<br>Your message has been sent.<br> We will get back to you as soon as we can.</font></p>';
    }
    else{
    echo '<p align="center"><font color="#FF0000">Please fill in all data!<br>All fields are obligatory.</font></p><p><a href="contactEN.html">[back]</a>';
    
    }
    }
    ?>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    When using the image, do you set the name as "Submit"? As a test, try taking out the

    Code:
    if ($_POST["Submit"];) {
    in the above code, and use the image in the html form.

    (Remember to take the last bracket ( } ) out of the php file or else it will cause an error once you take the first if statement out.)

    Another thing you could try is adding a hidden field in the form (let's call it "act") with a value (let's say "submit_form"). Then instead of the

    Code:
    if ($_POST["Submit"])
    part, change it to

    Code:
    if ($_POST["act"] == "submit_form")
    That's just two solutions. Let me know if you need further help.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Nov 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    the BEST way I have found to SUBMIT forms is to use INPUT TYPE=SUBMIT. Since you are saying that your form works with a submit button and not with an image button. Best bet is that there is not a problem with your php script.

    The solution to this problem is extremely simple. USE A SUBMIT BUTTON.

    The hidden type is a great technique posted above. I use this technique daily.

    As I posted earlier if you want your submit button to be an image then you can do that, best way is with CSS.

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I agree with everything that penguin stated above. And as said above

    The hidden type is a great technique posted above. I use this technique daily.
    I as well use it in just about all of my scripts and programs that I create, due to the fact that if you simply request in your PHP scripts the name of the form element (i.e.:
    Code:
    <input type="name" value="something">
    and
    PHP Code:
    if ($_POST[name]) 
    anybody could make the intended program cause an error, or cause the program to do something that was not intended when it was created. (If that makes any sense.)

    Also, as stated above, the best way to change the submit button is through css. This is yet another technique that I have personally used in programs and whatnot.

    Hopefully this helps you out.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    Sorry, but I am no expert at all in this matter.
    You say the .php is not secure. How would the above code look like if you let it be sent by an image, and secured for errors ?
    How would the css look like ?

  6. #6
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    Is the following correct ?

    Code for the contact.html

    Code:
    <html>
    <head>
    <script language="JavaScript" type="text/JavaScript">
    function clearDefault(el) {
    if (el.defaultValue==el.value) el.value = ""
    }
    </script>
    </head>
    <body background="bgpalet.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    
    <table width="80%" height="100%" border="0" cellpadding="0" cellspacing="0" align=right>
    <tr><td align="center" valign="middle">  
    
    <table border="0" width=100% align=right>
    <tr><td width="120" valign="middle">
    
    </td><td valign="middle" align="right">
    
    <FORM NAME="form1" METHOD="post" ACTION="contactEN.php">
    <input type="hidden" name="action" value="send">
    <table width="100%" valign="top" align=center>
    <tr><td>
    <table width=100%>
    <tr><td align=left>
    <INPUT TYPE=TEXT NAME="name" VALUE="your name" onFocus="clearDefault(this)" style="border:1px solid #666666; width:190px">
    </td></tr>
    <tr><td align=left>
    <INPUT TYPE=TEXT NAME="email" VALUE="your e-mail" onFocus="clearDefault(this)" style="border:1px solid #666666; width:190px">
    </td></tr></table>
    </td><td width=20>
    &nbsp</td><td align=left valign=middle>
    <INPUT TYPE="image" src="emailgo.jpg" NAME="submit" VALUE="go" style="border: 0px">
    </td></tr></table>
    
    <table width="100%" valign="top" align=center>
    <tr><td align=right>
    <TEXTAREA NAME="message" style="border:1px solid #666666; width:265px; height:120px">
    </TEXTAREA>
    </td></tr></table>
    <br>
    <table width="100%" valign="top" align=center>
    <tr><td align=center>
    <fieldset style="border:1px solid #666666; width:260px">
    tel: 0032.475.98.49.96
    </fieldset></td></tr></table>
    
    </FORM>
    
    </td></tr></table>
    </td></tr></table>
    
    </body>
    </html>
    Code for the contact.php:

    Code:
    <?
    if ($_POST["action"] == "send"){
    
    if ($_POST["name"] and $_POST["email"] and $_POST["message"] ){
    
    mail (
    "info@casariegoart.com",
    "via website (EN)",
    "
    Name:     ".$_POST['name']."
    E-mail:   ".$_POST['email']."
    Message:  ".$_POST['message']."
    
    ",
    "From: ".$_POST['name']." <".$_POST['email'].">");
    
    echo '<p align="center"><font color="#003366">Thanks !<br>Your message has been sent.<br> We will get back to you as soon as we can.</font></p>';
    
    }
    
    else{
    echo '<p align="center"><font color="#FF0000">Please fill in all data!<br>All fields are obligatory.</font></p><p><a href="contactEN.html">[back]</a>';
    
    }
    }
    ?>

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I have tested the above code, and it seems to work correctly. If you experience any problems with it, let me know and I'll see what I can do about it. Other than that, you should be good to go with the pages above.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #8
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    I received a test e-mail, I suppose it was yours ?
    Thank you so much !!!!!! I am starting now a fantastic day after three hours of traffic jam in Brussels, so again, someone unknown to me makes my day !

  9. #9
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    The form works well, thanks.
    But as in the first two fields there is already text written (your name, your e-mail), it is possible to send the mail by only filling in the text area.
    How can this be avoided ?
    And how ca

  10. #10
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    And how can I make sure that they fill in a valid email adres (with @ f.ex.) ?

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
  •