trim function issues
Posted on
16th Feb 2014 07:03 pm by
admin
Hi guys, total noob here...
So I've been tinkering around with a html and am using php to email the subitted data to me. It's all working fine, except now I've changed the rules of the form a little and I can't seem to make it do a very simple task of converting field data to a string so that I can have it in the body of the email.
Here's the code:
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['name']) == '') {
$hasError = true;
} else {
$name = trim($_POST['name']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'mickyginger@googlemail.com'; //Put your own email address here
$subject = 'Interest from the website';
$body = $name . $email;
$headers = 'From:' .$name. '<'.$email.'>' . "rn" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
Which works fine and dandy, only there are other fields like 'date' and 'venue' which I want to add to the body of the email regardless of whether they have been left blank or not.
Basically I want it to do something like this:
If the form is submitted
if name is not empty
$name = trim($_POST['name']);
if email is not empty
$email = trim($_POST['name']);
if number is empty OR if not
$number = trim($_POST['number']);
if date is empty OR if not
$date = trim($_POST['date']);
if there is no error
$body = $name . $email . $number . $date
seems like it should be really simple but I've tried everything I can think of with no joy...
No comments posted yet
Your Answer:
Login to answer
173
28
Other forums
Default TimeZone
The server I'm working with is hosted in America so all times inserted into the database are coming
why this query can delete duplicates ?
why this query can delete duplicates ? Anybody can give me the detailed explanation ?
Tha
ob_ dynamic content
i was wondering about the potential to use ob to create a <div then remove it when the page
C++ API to Oracle dB
I need to perform a select command to the Oracle dB to obtain information from a table.
What libr
Automatically Detect Phone Model for WAP Jar Deployment
Making a wap site is fairly simple, but I'd like to know if there's a way to make it so that the wap
Xacute search within SQL results
I have a query that is pulling data, and I want to return a specific value from the results of that
Help on code output
My CODE:
Code: [Select] echo "<phone>".$line["phone"].&qu
php mail form text wont appear / javascript included
Guys/gals...
I am running into a problem whereby I have a great piece of javascript code that
Asset Transfer from One plant to another within same company code
Hi,
Please advise how to transfer one asset from one plant to another plant within same c
Inserting Data into a MS Access DB using PHP.
As part of my uni course I am doing a placement at a company whom want me to create a client zone fo