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
Multiple server callbacks (NOT POSTBACKS)
Hello,
I have 2 different javascript client side functions that are on timers. When the timers elap
ALV sum various columns problem
Hi all,
I'm doing a report on ABAP for a timesheet of the current month. The output i want is s
rdns with php
I am trying to build a script that will show all of the different domains that are hosted on the sam
mySQL and PHP search
Hello,
I am trying to code a project and ran into a brick wall with one of my pages. I am pretty
Querying info from one table based on info in another
Hi, I am currently trying to make a part for my user driven website where one user can subscribe to
How to write on database when a link is clicked?
Hi,
I have a list of products in a gridview. When the link is clicked currently it takes to an ext
How to show next and prev records
Hi all,
Sorry if this is simple, i'm very new to php, well, any programming language actually
Probably Easy, Need help with Check Boxes in PHP Code
hello,
Thanks for looking this over and helping me out. My problem is I have a online store l
php form help
Hey,
I use a control file to set my meta tags and titles
Here's an example
Code: &a
Storing user data help?
Hey Guys,
I'm not use if this question is to broad but I can always give you more informatio