PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Sep 30, 2020 2:17 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Jun 13, 2014 6:02 am 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 5:55 am
Posts: 17
Ok i created a form everything works great except one thing that bothers me is once the data is sent to my email i receive the information firs_name, last_name with underscore and lower case. I would like to change that to FIRST NAME: Capital if possible or First Name: without no underscore, can someone please help me out on this i been searching a lot for this answer and have not found one yet.

This is how i have it and it does not let me change the input by First Name: only works as it is

<input name="First_Name" type="text" class="auto-style39" />


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 7:05 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Don't change it in the form, change it where you're mailing it out. Use a str_replace or preg_replace to remove the underscores in the $_POST array keys.


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 8:19 am 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 6:02 am
Posts: 4
$str = strtoupper($str); and str_replace(find,replace,string) use this 2 functions


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 4:05 pm 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 5:55 am
Posts: 17
Thank You so much for responding back. I am still new at this i am a bit confused as i do not know much about these $str = strtoupper($str); and str_replace(find,replace,string) use this 2 functions like where would i place them which section sorry i am a bit slow on this but i am trying to learn and i am using CGI Script to receive the data through out my webhosting if that matters.


Last edited by EdeniTX on Fri Jun 13, 2014 4:32 pm, edited 2 times in total.

Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 4:28 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
If you post the code where the form is being processed, we can show you exactly what changes to make.

Take a look at the PHP manual for and


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 4:33 pm 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 5:55 am
Posts: 17


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 4:37 pm 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 5:55 am
Posts: 17
My form is created in HTML, i used Expression Web 4.0


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 4:57 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
It's not the form itself we need so much as the code that processes the form after submission.


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 5:06 pm 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 5:55 am
Posts: 17
I am using the CGI Script from my webhosting HostGator.com everything is being processed through CGI. Is that what you are talking about?


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 5:09 pm 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 5:55 am
Posts: 17
Image

Image

<input type=hidden name="recipient" value="info@edenslimousine.com">
<input type=hidden name="required" value="First_Name,Last_Name,Cell_Phone,Email,Service_Type,Number_of_Passengers,Pick_Up_Date,Pick_Up_Time,Drop_Off_Time,Vehicle_Type,Pick_Up_Address,Drop_Off_Address">
<input type=hidden name="missing_fields_redirect"value="http://edenslimousine.com/Error/Error.html">
<input type=hidden name="redirect" value="http://edenslimousine.com/Success/Success.html">
<input type=hidden name="env_report" value="REMOTE_HOST,HTTP_USER_AGENT">
<input type=hidden name="subject" value="Reservation">


This is how i have it?


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 5:40 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Wow. Haven't seen a CGI script in ages. All of our suggestions above are now irrelevant. Are you able to edit the CGI script? If not, you may just need to live with first_name as that's where it's being processed.


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 5:48 pm 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 5:55 am
Posts: 17


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 7:09 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
The form itself doesn't need changing. You just need to remove the reference to the CGI and add some processing to it. In short, check if $_POST contains values (ie. the form has been submitted), then perform whatever operations you need to on those fields.

A quick and dirty example would be something like this:
Syntax: [ Download ] [ Hide ]
if (!empty($_POST)) {
        $text = '';
       
        foreach ($_POST as $key => value) {
                $text .= strtoupper(str_replace('_', ' ', $key)) . ": {$value}\n";
        }

        $to = $_POST['recipient'];
        $subject = $_POST['subject'];

        mail($to, $subject, $text);
}


Top
 Profile  
 
PostPosted: Fri Jun 13, 2014 10:00 pm 
Offline
Forum Newbie

Joined: Fri Jun 13, 2014 5:55 am
Posts: 17


Top
 Profile  
 
PostPosted: Sat Jun 14, 2014 9:02 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
If you're just getting started, check out . Most PHP tutorials online, unfortunately, are terrible; out of date, full of bad practices, and generally written by people who don't really know what they're talking about. This is one of the very few good ones and should serve you well.

As for the bit of code I posted above, the body of the email is being stored in the variable $text before being passed to the mail() function. You can add whatever text you like before or after the form fields by simply appending to the variable. Place the block of code at the top of your PHP file.

Syntax: [ Download ] [ Hide ]
<?php
if (!empty($_POST)) {
        $text = '';
       
        $text .= "This text will appear at the beginning of the email body.";

        // This loop will add ALL the form's values to your email
        foreach ($_POST as $key => value) {
                $text .= strtoupper(str_replace('_', ' ', $key)) . ": {$value}\n";
        }

        $text .= "This text will be appended after the form fields.";

        $to = $_POST['recipient'];
        $subject = $_POST['subject'];

        mail($to, $subject, $text);
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group