Grow your CSS skills. Land your dream job.

Contact Post not displaying information

  • # February 18, 2013 at 12:18 pm

    I don’t know why that font showed up so big, I apoligize..

    # February 18, 2013 at 12:24 pm

    You have to highlight it and press the ‘Code’ option.

    I fixed that bit

    # February 18, 2013 at 12:28 pm

    So, if you’re going to use @traq‘s code raw you need to change the `method` attribute on the `form` tag to “post” instead of “get”.

    I know you’re having issues with styling but let’s get the form working before worrying about that :)

    # February 18, 2013 at 3:59 pm

    Just to clarify, there is nothing wrong with placing your inputs inside their labels – in fact, if you do, you don’t need to use the `for` attribute. It’s not very common practice, and, as you’ve seen, it does affect how you approach styling.

    Also, sorry! I didn’t notice earlier that you were using the GET method. POST is preferable, in this case. Say you have a form that looks like this:






    Your `submit.php` script might look something like this:

    < ?php
    # only if the form was submitted
    if( !empty($_POST) ){

    # get submitted name
    $name = empty( $_POST )?
    ‘no name submitted’:
    $_POST;

    # get submitted email
    $email = empty( $_POST )?
    ‘no email submitted’:
    $_POST;

    # get submitted message
    $message = empty( $_POST )?
    ‘no message submitted’:
    wordwrap( $_POST,70 );

    # send email to:
    $to = ‘you@example.com’;

    # prepare email subject
    $subject = ‘Someone submitted your form!’;

    # prepare email body
    $body = < << TEXT
    Name: $name
    Email: $email
    Message:


    $message
    TEXT
    ;

    # prepare email headers
    # the email IS NOT “from” the user, it’s from your website.
    # saying it’s “from” the user will get it caught by spam traps.
    $headers = “From: noreply@example.comrn“;

    # send email
    if( mail( $to,$subject,$message,$headers ) ){
    print ‘Thanks for sending your message!’;
    }else{
    print ‘There was a problem – please try again.’;
    }
    }

    Note that this is very basic, and doesn’t even make any fields “required.” You’d probably want to make sure that the “email” submitted is really an email address, that the message is not blank, etc.. But this is a solid base to start changing for your needs.

    # February 18, 2013 at 7:21 pm

    So this is the form I have so far.. I uploaded it and it still doesn’t seem to be working.

    And I did change the Method to post.





    Clear      Send

    This is the PHP file that I have so far..

    < ?php
    # only if the form was submitted
    if( !empty($_POST) ){

    # get submitted name
    $name = empty( $_POST )?
    ‘no name submitted’:
    $_POST;

    # get submitted email
    $email = empty( $_POST )?
    ‘no email submitted’:
    $_POST;

    # get submitted message
    $message = empty( $_POST )?
    ‘no message submitted’:
    wordwrap( $_POST,70 );

    # send email to:
    $to = ‘you@example.com’;

    # prepare email subject
    $subject = ‘Someone submitted your form!’;

    # prepare email body
    $body = < << TEXT
    Name: $name
    Email: $email
    Message:


    $message
    TEXT
    ;

    # prepare email headers
    # the email IS NOT “from” the user, it’s from your website.
    # saying it’s “from” the user will get it caught by spam traps.
    $headers = “From: noreply@example.comrn“;

    # send email
    if( mail( $to,$subject,$message,$headers ) ){
    print ‘Thanks for sending your message!’;
    }else{
    print ‘There was a problem – please try again.’;
    }
    }

    # February 18, 2013 at 7:34 pm

    Your $_POST names must match your input names.

    If the input name is “Name” then your POST name must be $_POST and if your email input name is “E-mail” then your POST name needs to be $_POST and so on.

    # February 18, 2013 at 8:01 pm

    Okay, I think I fixed that as well. I uploaded the changes and tried to comment on it again, but it appears as though I am still not receiving the message..

    # February 18, 2013 at 8:22 pm

    Your initial check of seeing whether the $_POST !empty will always be false with the way your form is setup. Instead of using “a” elements to submit the form use

    and then style to submit button to suite your design.

    # February 18, 2013 at 9:45 pm

    …or, use

    if( !empty( $_POST ) )

    instead.

    *****

    Nothing against this forum, or codepen, but neither are suitable for sharing more than a few lines of PHP code. I suggest creating a [gist on github](http://gist.github.com).

    You can [fork this](https://gist.github.com/customanything/4982644) if you want to edit it. The only thing I changed is the `if` check and the POST index names (so they match your input names).

    # February 19, 2013 at 8:41 am

    I forked it, and its located here [https://gist.github.com/windbertsa/4985808](https://gist.github.com/windbertsa/4985808 “windbertsa.php”) I changed the first statement for the way it initially submits it to match the way I had the form set up( I suppose that will save me a little bit of time in the future with styling the buttons and things)

    In my text editor, it keeps saying that I have an error on line 38, which is where the if( mail( $to,$subject,$message,$headers ) ){ line is..

    I did upload the changes I made again, the form is still appearing to have problems.

    And thank again for all of your help!

    # February 19, 2013 at 7:54 pm

    I keep trying to go through the php file, but I can’t figure out what would be wrong. Everything matches the form and it’s just like @traq posted, so I don’t understand why the message isn’t sending.

    # February 19, 2013 at 10:02 pm

    > In my text editor, it keeps saying that I have an error on line 38, which is where the if( mail( $to,$subject,$message,$headers ) ){ line is..

    What is the error?

    **edit**

    It should be `$body`, not `$message`. Sorry about that

    > if( !empty( $_POST ) )

    You have no form element named `message`. After your form is submitted, `$_POST` will contain three indexes: `Name`, `E-mail`, and `comments`.

    # February 19, 2013 at 10:36 pm

    I changed that to $body. I haven’t done much at all with PHP and in dreamweaver it didn’t show me what the error was, just highlighted that section..

    And okay, I think I finally understand the $_POST part! I changed $message to $comments. And I uploaded the changes again. I don’t seem to have received an email after sending it..

    If I am not receiving the print after submitting the post, is that an indicator something before that in the code isn’t executing correctly?

    On a side note, I’m not sure how to highlight code elements in yellow like you do..

    # February 20, 2013 at 1:10 am

    > On a side note, I’m not sure how to highlight code elements in yellow like you do..

    `this` → `this`

    it’s [markdown](http://daringfireball.net/projects/markdown/syntax), baby!

    > in dreamweaver it didn’t show me what the error was, just highlighted that section..

    ugh… no offense. You need a code editor for writing code, which Dreamweaver is not. (You might look at something like [komodo](http://www.activestate.com/komodo-edit).) Try it on a real server, and make sure error reporting is enabled -

    < ?php
    error_reporting( -1 );
    ini_set( ‘display_errors’,1 );

    # rest of code here

    > If I am not receiving the print after submitting the post, is that an indicator something before that in the code isn’t executing correctly?

    Right – that would indicate that code execution does not reach the point where it tries to send the mail. If it did, then you’d get either the “Thanks” or “Problem” message. Two possibilities:

    … you’re not entering the initial `if( !empty( $_POST ) )` block

    … you’re encountering a fatal error before the call to `mail()` is complete

    If it’s the latter, then setting error reporting should tell us so. During development, it’s always a good idea to make sure you see **every last error**. During production, it’s a good idea to hide them (from the public; *you* should still keep an eye on your error logs).

    # February 20, 2013 at 8:11 am

    Okay, so `this` would create that effect.

    > You need a code editor for writing code, which Dreamweaver is not. (You might look at something like komodo.)

    I am downloading komodo and I will try it out :) I am not sure how that will effect what I am used to. I do not use like the WYSISYG feature of dreamweaver, I just liked the way it was set up for managing all the files, the code hints, and the design view can show me a lot of what I am doing before I have to preview it in multiple browsers(My High School uses it and it seemed like a good idea).

    > Try it on a real server,

    What do you mean by real server? I have been uploading the changes to my iPage hosting and testing the post on the actual web page..

    I added that Code snippet for the error reporting and that block matches up. What I have on the [https://gist.github.com/windbertsa/4985808](https://gist.github.com/windbertsa/4985808 “gist”) is exactly what I have in the PHP file.

    > If it’s the latter, then setting error reporting should tell us so.

    How will it ‘tell’ me what the error is?

Viewing 15 posts - 16 through 30 (of 48 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".