Web Design Forums

PHP

Have questions about PHP? Ask them here and our experts will assist you before you know it! You can also find help in the documentation at PHP.net.

Having trouble with "submit" button php function



Site of the Month Nominations
ENTER YOUR SITE NOW!

Reply
 
LinkBack Thread Tools
Old June 15 '09, 09:42 AM (#1)
TWyPGn is offline
WDF Member
 
TWyPGn's Avatar
 
Join Date: March 2009
Posts: 21
TWyPGn is an unknown quantity at this point
Having trouble with "submit" button php function

Hello, I am making a contact form for my website with a submit button where a form data is sent to you through email, and it also generates a message "Thank you for your interest. We'll respond to you shortly" after the "submit" button is clicked.

For the php script for submit button, I took help from Elizabeth Castro's book "HTML, XHTML & CSS", but it is not generating the desired output, instead the script page opens on clicking submit. Let me mention here that I don't know anything about php/javascript. Following are the html codes for the contact form, and php code for submit button:

HTML:


PHP Code:
       <div id="form">

                <form action="emailform.php" method="post">
                
                    <p class="legend">Personal Information</p>
                    
                    <fieldset id="personal">
                        <label>Name:</label><input type="text" name="name" size="30" maxlength="40" /> <br />
                        <label>City &amp; Country:</label><input type="text" name="city &amp; country" size="30" /> <br />

                        <label>Phone:</label><input type="text" name="phone" size="30" /> <br />
                        <label>Email Address:</label><input type="text" name="email address" size="30" maxlength="40" /><br /> 
                        
                    </fieldset>


                    <p class="legend">Subject</p>
                    
                    <fieldset id="choices">

                        <p id="subject"><label>Tell us what your query is about:</label>
                        <select name="subject" >
                            <option value="Product Inquiry">Product Inquiry</option>
                            <option value="Order Inquiry">Order Inquiry</option>
                            <option value="Shipping Inquiry">Delivery Inquiry</option>
                            <option value="General Inquiry">General Inquiry</option>
                        </select>
                        </p>

                    </fieldset>

                    <p class="legend">Your question or message here</p>
                    
                    <fieldset id="questions">

                        <textarea name="comments" rows="3" cols="40">Yor questions or message here</textarea>
                    </fieldset>
                    
                    <p id="buttons">
                        <input type="submit" name="submit" value="Submit"  />
                    </p>
                    
                </form>
            </div>

[B]PHP from Elizabeth Castro's website:[/B]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Emailing Form Data</title>
<style type="text/css">
code {color:#F00C4D;font-weight:bold;font-size:1.2em}
i {color: #6D0CF0}
th, td {padding:.1em;border:1px solid blue;text-align:left}
</style>
</head>
<body>


<?php
//This is a very simple PHP script that outputs the name of each bit of information (that 
//corresponds to the <code>name</code> attribute for that field) along with the value that was
//sent with it right in the browser window, and then sends it all to an email address (once you've
//added it to the script).

if (empty($_POST)) {
    print 
"<p>No data was submitted.</p>";
    print 
"</body></html>";
    exit();
}

//Creates function that removes magic escaping, if it's been applied, from values and then 
removes extra newlines and returns to foil spammersThanks Larry Ullman!
function 
clear_user_input($value) {
    if (
get_magic_quotes_gpc()) $value=stripslashes($value);
    
$valuestr_replace"\n"''trim($value));
    
$valuestr_replace"\r"''$value);
    return 
$value;
    }


if (
$_POST['comments'] == 'your questions or comments here'$_POST['comments'] = '';    

//Create body of message by cleaning each field and then appending each name and value to it

$body ="Here is the data that was submitted:\n";

foreach (
$_POST as $key => $value) {
    
$key clear_user_input($key);
    
$value clear_user_input($value);
    if (
$key=='extras') {
        
    if (
is_array($_POST['extras']) ){
        
$body .= "$key: ";
        
$counter =1;
        foreach (
$_POST['extras'] as $value) {
                
//Add comma and space until last element
                
if (sizeof($_POST['extras']) == $counter) {
                    
$body .= "$value\n";
                    break;}
                else {
                    
$body .= "$value, ";
                    
$counter += 1;
                    }
                }
        } else {
        
$body .= "$key: $value\n";
        }
    } else {

    
$body .= "$key: $value\n";
    }
}

extract($_POST);
//removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers
$email clear_user_input($email);
$name clear_user_input($name);

//Create header that puts email in From box along with name in parentheses and sends bcc to alternate address
$from='From: '$email "(" $name ")" "\r\n" 'Bcc: [EMAIL="yourmail@yourdomain.com"]yourmail@yourdomain.com[/EMAIL]' "\r\n";


//Creates intelligible subject line that also shows me where it came from
$subject 'Query from Web Site';

//Sends mail to me, with elements created above
mail ('youremail@yourdomain.com'$subject$body$from);


?>

<p>Thanks for your interest! We'll respond to you shortly.</p>


</body>
</html>
-----------------------------------
If anybody could please help me with this php code and submit button to work properly, I'll be very grateful. Thanks!

Last edited by Wired; June 15 '09 at 05:38 PM. Reason: added BBCODE
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 15 '09, 09:48 AM (#2)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
turning off magic quotes is problematic at best. host can keep this from working. the right way to go about this is to use $value = urlencode($value); and just ditch the stripslashes and magic workaround. you will need urldecode on the other end.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 15 '09, 09:05 PM (#3)
TWyPGn is offline
WDF Member
 
TWyPGn's Avatar
 
Join Date: March 2009
Posts: 21
TWyPGn is an unknown quantity at this point
Thanks Dorky for replying with a solution to fix the problem. Here let me say that I don't know ANYTHING about php. So I don't know what the submit php code is and how to edit it. So I'll appreciate if you could tell me how to edit the php code through exact script. Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 15 '09, 09:22 PM (#4)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
ok i im not the guy to teach php, im still learning. so instead ill share a small yet functional mail script that doesnt require so much changing and overhead.


//this part goes in an html file you create. mine is msg.html
<head>
</head>
<body>
<html>
<form method='post' action='sendmail.php'>
Contact Info:<input class='textarea' name='email' type='text' /><br/><br/>
Drop us a Line:<br/>
<textarea class='textarea' name='message' rows='25' cols='50' >
</textarea><br/>
<button name='submit' type='submit' class='submit'>Send Mail</button>
</form>
</body>
</html>

//then this goes in a php file. i call mine sendmail.php
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "you@yoursite.com", "Site Mail",
$message, "From: $email" );
echo "Thank You";
?>

small but it does just what i want.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 16 '09, 04:42 PM (#5)
TWyPGn is offline
WDF Member
 
TWyPGn's Avatar
 
Join Date: March 2009
Posts: 21
TWyPGn is an unknown quantity at this point
Thanks a lot Dorky for the php code. It works. Do you any simple online tutorials on PHP that teach more complex php submit code? I have come across online tutorials but I don't understand anything. Or if you could suggest any books on php, I'll appreciate that. Anyway, thanks once again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 16 '09, 05:22 PM (#6)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
www.w3schools.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 16 '09, 07:16 PM (#7)
TWyPGn is offline
WDF Member
 
TWyPGn's Avatar
 
Join Date: March 2009
Posts: 21
TWyPGn is an unknown quantity at this point
Thanks Dorky! Hope I'm able to get the help from "w3schools" tutorials. Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 01:01 PM (#8)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
no prob. hope it helps. when w3schools doesnt elaborate enough to get the point made come here and we will solve it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 05:12 PM (#9)
TWyPGn is offline
WDF Member
 
TWyPGn's Avatar
 
Join Date: March 2009
Posts: 21
TWyPGn is an unknown quantity at this point
Hello, still no luck in getting my "submit" button work. I wanted to know if submit button php code works when the website is launched, or can one check its working in design phase. I have tried various php codes that send data to an email but nothing has worked. I thought since I haven't launched the website it might not be working properly. Please help!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 05:21 PM (#10)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
would need your server info before making that call as far as how you are testing at this point.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 05:24 PM (#11)
TWyPGn is offline
WDF Member
 
TWyPGn's Avatar
 
Join Date: March 2009
Posts: 21
TWyPGn is an unknown quantity at this point
I haven't launched the website yet. I think launching the website and then running the php code might suggest where the problem is. What do you think? Anyway, thanks for replying.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 05:25 PM (#12)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
yeah if you dont have it on a server with php installed it wont work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 05:28 PM (#13)
Wired is online now
WDF Alien Overlord
 
Wired's Avatar
 
Join Date: April 2003
Posts: 6,421
Wired is just really niceWired is just really niceWired is just really niceWired is just really nice
Send a message via AIM to Wired
How to Send Email from a PHP Script

Configure PHP to Use a Local Mail Server for Sending Mail
How to Configure PHP to Use a Remote SMTP Server for Sending Mail

In short, you have to check your php.ini under the [mail function] to make sure it's set up correctly. Otherwise, you can't use the mail() function.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 05:33 PM (#14)
TWyPGn is offline
WDF Member
 
TWyPGn's Avatar
 
Join Date: March 2009
Posts: 21
TWyPGn is an unknown quantity at this point
Thanks! By the way how do I know if the server or my web host has php installed?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 05:39 PM (#15)
TWyPGn is offline
WDF Member
 
TWyPGn's Avatar
 
Join Date: March 2009
Posts: 21
TWyPGn is an unknown quantity at this point
Thanks Wired for sending the links of articles on this form-email stuff. I hope all this helps. I am total novice in php, so really don't have any idea what to do or what is required. Anyway, thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 17 '09, 06:12 PM (#16)
Wired is online now
WDF Alien Overlord
 
Wired's Avatar
 
Join Date: April 2003
Posts: 6,421
Wired is just really niceWired is just really niceWired is just really niceWired is just really nice
Send a message via AIM to Wired
Ask your host what you are paying for.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » PHP

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Top 21 PHP Programming mistakes thexchord PHP 19 June 18 '10 02:20 PM
php radio button form ketanco PHP 4 September 28 '08 11:51 AM
JS menu alignment in IE robbieM Javascript, AJAX, and JSON 0 January 28 '05 10:33 AM
Will pay for custom php function jf1288 For Hire / Wanted 0 December 19 '04 02:20 AM
Timer krazy Javascript, AJAX, and JSON 172 July 16 '03 01:38 PM

 
User Infomation
Your Avatar

Site Of The Month

Ticket Cake
Ticket Cake

Ticket Cake is a drupal based event ticketing platform. It features that ability to browse events and share them.

Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:47 AM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163