Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Problem with PHP form

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #32548
    Waffle
    Member
    
    
    if ( !isset ( $_POST ) ) : ?>





















    if ( !$_POST || !$_POST || !$_POST || !$_POST ) :

    print 'You left something blank.';

    else :

    print 'Message sent!';



    $body = $_POST . 'n' .

    $_POST . 'n' .

    $_POST . 'nn' .

    $_POST;


    mail('[email protected]', "You've got mail!", $body);

    endif;

    endif;

    ?>

    I’d like to style

    print 'You left something blank.';

    And also make it so that when Submit button is clicked, the form does not disapear. because thats rather annoying .

    Any help with this would be appreciated

    #48721
    TT_Mark
    Member

    To style the text, wrap it in a paragraph or span and give it a class or id e.g.


    print '

    You left something blank

    ';

    Then style it in the CSS file

    #48709
    ChrisBull
    Member

    I would recommend restructuring the page.
    Keep it all in one file but have all of the php at the top and the html form at the bottom, like this,


    PHP Code
    ?>

    HTML Form

    In the php section you can check if the form has been filled and posted to itself and if it has send the mail, if it hasn’t ie the viewing the page for the first time don’t do anything so they see the form, and if there are errors with the entries, display to form still but put echo statements inside the html code to display the errors.

    Hope that helps

    #48706
    Waffle
    Member

    Haha, I’m sorry, It doesn’t really help, Could you show me an example?

    + With restructuring the code, that wouldnt work with the code I have written because

    if ( !isset ( $_POST ) ) : ?>

    Says Submit the form.. which is below.. and the form is below.. so I’d have to rewrite it.. and tbh, Thats the only way I know how…

    A little example would help me :)

    #48636
    ChrisBull
    Member

    You should have this all inside one .php file



    $speech = "";
    if(isset($_POST)) {
    if ( $_POST == "" || $_POST == "" || $_POST =="" || $_POST =="" ) {
    $speech = "You've Left Something Blank.";
    } else {
    $body = $_POST . 'n' .
    $_POST . 'n' .
    $_POST . 'nn' .
    $_POST;
    mail('[email protected]', "You've got mail!", $body);
    //////Either have Speech Variable = to text so...
    $speech = "Message Has been Sent!";
    //////Or redirect to page to another .php page
    header('Location: http://www.example.com/');
    }
    }

    ?>



















    Try that, and tell me what happens

    #48577
    Waffle
    Member

    I get Syntax errors on 3 of the Labels.. I

    #48573
    Waffle
    Member

    That PHP Script should be all on the same page right?

    #48563
    ChrisBull
    Member

    Try it again, i’ve corrected the mistakes i made in the code

    #48549
    Waffle
    Member

    Oh wow, Brilliant! Thank you SO much Chris.

    works epicly

    #48550
    Waffle
    Member

    Ohhh Wait. However. It gives me an error when It sends.. It works but the error appears and thats bad.

    Warning: Cannot modify header information - headers already sent by (output started at /home/coadtcom/public_html/contact.php:9) in /home/coadtcom/public_html/contact.php on line 80

    Says that. Not good, Any ideas?

    #48527
    ChrisBull
    Member

    Have you got any other code on your page that i didn’t write?
    Copy your file and paste all the code here so i can see

    #48522
    Waffle
    Member








































    Contact Options










    Drop us a line



    $speech = "";
    if(isset($_POST)) {
    if ( $_POST == "" || $_POST == "" || $_POST =="" || $_POST =="" ) {
    $speech = "

    You've Left Something Blank.

    ";
    } else {
    $body = $_POST . 'n' .
    $_POST . 'n' .
    $_POST . 'nn' .
    $_POST;
    mail('[email protected]', "you've got mail!", $body);
    //////Either have Speech Variable = to text so...
    $speech = "

    Message Has been Sent!

    ";

    header('Location: http://coadin-internet.com');
    }
    }

    ?>































    #48439
    ChrisBull
    Member

    ok – error code was because you have html code before the php header request.
    In the code I gave you i left you with 2 choices, have the form still displayed after the mail has been sent but with a title of ‘Message Has been Sent!’ or have the page redirect to another page – you have left both but changed the location of the redirect…
    So do you want, 1. The form still displayed with ‘Message Sent’ or 2. The page to redirect to another page?

    #48427
    ChrisBull
    Member

    This will fix it either way – you need to choose between the two options



    $speech = "";
    if(isset($_POST)) {
    if ( $_POST == "" || $_POST == "" || $_POST =="" || $_POST =="" ) {
    $speech = "

    You've Left Something Blank.

    ";
    } else {
    $body = $_POST . 'n' .
    $_POST . 'n' .
    $_POST . 'nn' .
    $_POST;
    mail('[email protected]', "you've got mail!", $body);


    //////CHOOSE BETWEEN NEXT TO LINES AND REMOVE THIS ONE///////////
    $speech = "

    Message Has been Sent!

    ";
    header('Location: http://coadin-internet.com');
    }
    }

    ?>








































    Contact Options










    Drop us a line



































    #48380
    ChrisBull
    Member

    Also – If you choose to redirect the use to another page make sure it’s to a page that confirms the message has been sent, if they just get redirected to your home page they will be left wondering what has happened.

    There are yet better ways to structure this still – For instance you could have the main file with the php code in, and then two seperate files, one that contains the code for the form and one that contains code for a message sent page, and then depending on whether the form has been sent on not you can use require_once(‘nameofpage.php’) to either display form or message sent page.

Viewing 15 posts - 1 through 15 (of 16 total)
  • The forum ‘Back End’ is closed to new topics and replies.