- This topic is empty.
-
AuthorPosts
-
April 29, 2011 at 2:51 pm #32548WaffleMember
if ( !isset ( $_POST ) ) : ?>
else :
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
April 29, 2011 at 4:29 pm #48721TT_MarkMemberTo 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
April 29, 2011 at 5:53 pm #48709ChrisBullMemberI 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
April 29, 2011 at 6:43 pm #48706WaffleMemberHaha, 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 :)
April 29, 2011 at 7:07 pm #48636ChrisBullMemberYou 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
April 30, 2011 at 8:30 am #48577WaffleMemberI get Syntax errors on 3 of the Labels.. I
April 30, 2011 at 8:56 am #48573WaffleMemberThat PHP Script should be all on the same page right?
April 30, 2011 at 9:13 am #48563ChrisBullMemberTry it again, i’ve corrected the mistakes i made in the code
April 30, 2011 at 9:43 am #48549WaffleMemberOh wow, Brilliant! Thank you SO much Chris.
works epicly
April 30, 2011 at 9:45 am #48550WaffleMemberOhhh 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?
April 30, 2011 at 9:49 am #48527ChrisBullMemberHave 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 seeApril 30, 2011 at 9:51 am #48522WaffleMember
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');
}
}
?>
April 30, 2011 at 9:57 am #48439ChrisBullMemberok – 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?April 30, 2011 at 10:05 am #48427ChrisBullMemberThis 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');
}
}
?>
April 30, 2011 at 10:07 am #48380ChrisBullMemberAlso – 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.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.