Forums

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

Home Forums Back End Contact Post not displaying information Re: Contact Post not displaying information

#125124
__
Participant

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:

# 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 = ‘[email protected]’;

# 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: [email protected]”;

# 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.