Guest nbdesign Posted September 28, 2005 Report Share Posted September 28, 2005 hi,i am new to php scripting. and i have looked through the php tutorial on w3schools siteand did not find the answer to my question.is it possible to send a name and last name or email address to a email address witha submit button, plus have this submit button take you to a web page?it's like asigning two different functions to one button! (i think, and i hope this has something to do with php)HELP! Quote Link to post Share on other sites
kaijim 15 Posted September 29, 2005 Report Share Posted September 29, 2005 Hello nbdesign.I just moved your post to a more sutable location Quote Link to post Share on other sites
kaijim 15 Posted September 29, 2005 Report Share Posted September 29, 2005 This is possible.This is the php file I use for these kind of things (I got this from someone a while back, so I can't really take credit for it ):2 Steps:First you create a php file.File: formmail.php (code below)Then you create a form in the page you wish to display this (Code for form at bottom of post),1. File: formmail.php Code: <?function parse_form($array) { // reserverte ord $reserved_keys[] = "require"; $reserved_keys[] = "recipient"; $reserved_keys[] = "subject"; $reserved_keys[] = "bgcolor"; $reserved_keys[] = "text_color"; $reserved_keys[] = "link_color"; $reserved_keys[] = "vlink_color"; $reserved_keys[] = "alink_color"; $reserved_keys[] = "title"; $reserved_keys[] = "missing_fields_redirect"; $reserved_keys[] = "env_report"; if (count($array)) { while (list($key, $val) = each($array)) { $reserved_violation = 0; for ($ri=0; $ri<count($reserved_keys); $ri++) { if ($key == $reserved_keys[$ri]) { $reserved_violation = 1; } } if ($reserved_violation != 1) $content .= "\t$key: $val\n<br>"; } } return $content;}// Send innholdet som epostfunction mail_it($content, $subject, $email, $recipient) { mail($recipient, $subject, $content, "From: $email\r\nReply-To: email\r\nX-Mailer: DT_formmail");}function build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color) { if ($title) echo "<title>$title</title>"; if (!$bgcolor) $bgcolor = "#FFFFFF"; if (!$text_color) $text_color = "#000000"; if (!$link_color) $link_color = "#0000FF"; if (!$vlink_color) $vlink_color = "#FF0000"; if (!$alink_color) $alink_color = "#000088"; if ($background) $background = "background=\"$background\""; echo "<body bgcolor=\"$bgcolor\" text=\"$text_color\" link=\"$link_color\" vlink=\"$vlink_color\" alink=\"$alink_color\" $background>\n\n";}function print_error($reason,$type = 0) { build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color); if ($type == "missing") { ?> The form was not submitted for the following reasons:<p> <ul><? echo $reason."\n"; ?></ul> Please use your browser's back button to return to the form and try again.<? } else { // alle andre error ?> The form was not submitted because of the following reasons:<p> <? } echo "<br><br>\n"; exit;}if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $recipient)) { print_error("<b>I NEED VALID RECIPIENT EMAIL ADDRESS TO CONTINUE</b>");}if ($require) { $require = ereg_replace( " +", "", $require); $required = split(",",$require); for ($i=0;$i<count($required);$i++) { $string = trim($required[$i]); if((!(${$string})) || (!(${$string}))) { if ($missing_fields_redirect) { header ("Location: $missing_fields_redirect"); exit; } $require; $missing_field_list .= "<b>Missing: $required[$i]</b><br>\n"; } } if ($missing_field_list) print_error($missing_field_list,"missing");}if (($email) || ($EMAIL)) { $email = trim($email); if ($EMAIL) $email = trim($EMAIL); if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $email)) { print_error("your <b>email address</b> is invalid"); } $EMAIL = $email;}$content = parse_form($HTTP_POST_VARS);if ($env_report) { $env_report = ereg_replace( " +", "", $env_report); $env_reports = split(",",$env_report); $content .= "------ eviromental variables ------"; for ($i=0;$i<count($env_reports);$i++) { $string = trim($env_reports[$i]); if ($env_reports[$i] == "REMOTE_HOST") $content .= "REMOTE HOST: ".$REMOTE_HOST."\n"; else if ($env_reports[$i] == "REMOTE_USER") $content .= "REMOTE USER: ". $REMOTE_USER."\n"; else if ($env_reports[$i] == "REMOTE_ADDR") $content .= "REMOTE ADDR: ". $REMOTE_ADDR."\n"; else if ($env_reports[$i] == "HTTP_USER_AGENT") $content .= "BROWSER: ". $HTTP_USER_AGENT."\n"; }}mail_it($content, $subject, $email, $recipient);if ($redirect) { header ("Location: $redirect"); exit;} else { print "Takk for bestillingen\n";}?> 2. FormCode: <form name="form1" method="post" action="http://some-url-for-your-webpage/formmail.php"> <input type=hidden name="recipient" value="youremail@somewhere.com"> <input type=hidden name="subject" value="Topic"> <input type=hidden name="required" value="Name,Text"> <input type=hidden name="redirect" value="http://tb31.homeip.net/takk.htm"> Name<br><input type=text name="Name" size="20"><br />Some Text:<br /> <textarea name="Text" rows="5" cols="50"></textarea><br> <br><input type="submit" name="Submit" value="Submit"> </form> There, this should be pretty much cut and paste for you, just change a few things in the form(URL, email, and maybe the values you want to send. Quote Link to post Share on other sites
alzable 0 Posted September 29, 2005 Report Share Posted September 29, 2005 Hmm, looks very helpful for what im doing at the moment. Can you make any form you like with the same script (the formmail.php one)?Or is the code you have there specificly designed for what nbdesign is doing.alzable Quote Link to post Share on other sites
kaijim 15 Posted September 29, 2005 Report Share Posted September 29, 2005 You can use it on any form. I used it for a low tech ordering system, with name, phonenumber, date and so on. Quote Link to post Share on other sites
alzable 0 Posted September 29, 2005 Report Share Posted September 29, 2005 Great! thanks, It will help me too!EDIT:IT'S PERFECT FOR WHAT I NEED! THANKS ALOT! Quote Link to post Share on other sites
jpkuelho 0 Posted May 27, 2007 Report Share Posted May 27, 2007 this worked for me to, the only problem is it sends the form even if the required fields are blank, and before it gave me a header error so I had to comment out these lines : header ("Location: $redirect"); exit;} else also whats the function of these <input type=hidden name="redirect" value="http://tb31.homeip.net/takk.htm">and how to make the form only send if the fields are filled ?I tought I only had to change these -> <input type=hidden name="required" value="email, nome, address, addressnumber, complemento, CEP, cidade" />thats what i did on mine ;/ Quote Link to post Share on other sites
zppblood 0 Posted May 27, 2007 Report Share Posted May 27, 2007 this worked for me to, the only problem is it sends the form even if the required fields are blank, and before it gave me a header error so I had to comment out these lines : header ("Location: $redirect"); exit;} else also whats the function of these <input type=hidden name="redirect" value="http://tb31.homeip.net/takk.htm">and how to make the form only send if the fields are filled ?I tought I only had to change these -> <input type=hidden name="required" value="email, nome, address, addressnumber, complemento, CEP, cidade" />thats what i did on mine ;/That's not a really good idea because it can easily be changed. Try using !empty() in a conditional to see if all required fields are filled out. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.