PHP - How To Get Html Form Data Into Php Function Arguments Using Ajax?
The Business Logic is: If product is already purchased, upgrade the product I have a customer input form to get information, along with some fields which should be auto populated based on what the customer chooses. Screen Shot:
https://i.stack.imgur.com/Fkyim.png When we come to the shipping cost I am getting it from Magento, using a PHP function. form :
https://paste.ofcode.org/335FVUhpBGbazQtrcPLVQUs sp_cost.php
https://paste.ofcode.org/hvG2sP9TW9CEPgMMuKXNuw $results = getShippingEstimate('14419','1',"IN","642001"); How can i get country and zipcode from the user entry and return the shipping cost?
Edited April 26, 2019 by aveeva Similar TutorialsI had this working, but when I try and get fancy and use AJAX the data doesn't display. I think this is a PHP problem though. My code for the select form including AJAX code Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB"> <head> <title>AJAX Example</title> <link rel="stylesheet" type="text/css" href="Form.css" media="screen" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("tr:odd").addClass("odd"); }); </script> <script type="text/javascript"> function showPlayers(str) { var xmlhttp; if (str=="") { document.getElementById("DataDisplay").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); else {// code for IE6, IE5 } xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("DataDisplay").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","Query.php?category_id="+str,true); xmlhttp.send(); } </script> </head> <body> <h1">AJAX Example</h1> <?php #connect to MySQL $conn = @mysql_connect( "localhost","username","pw") or die( "You did not successfully connect to the DB!" ); #select the specified database $rs = @mysql_SELECT_DB ("MyDB", $conn ) or die ( "Error connecting to the database test!"); ?> <form name="sports" id="sports"> <legend>Select a Sport</legend> <select name="category_id" onChange="showPlayers(this.value)"> <option value="">Select a Sport:</option> <?php $sql = "SELECT category_id, sport FROM sports ". "ORDER BY sport"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['category_id']."\">".$row['sport']."</option>\n "; } ?> </select> </form> <br /> <div id="DataDisplay"></div> </body> </html> Query.php <?php #get the id $id=$_GET["category_id"]; #connect to MySQL $conn = @mysql_connect( "localhost","username","pw") or die( "Error connecting to MySQL" ); #select the specified database $rs = @mysql_SELECT_DB ("MyDB", $conn ) or die ( "Could not select that particular Database"); #$id="category_id"; #create the query $sql ="SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = '".$id."'"; echo $sql; #execute the query $rs = mysql_query($sql,$conn); #start the table code echo "<table><tr><th>Category ID</th><th>Sport</th><th>First Name</th><th>Last Name</th></tr>"; #write the data while( $row = mysql_fetch_array( $rs) ) { echo ("<tr><td>"); echo ($row["category_id"] ); echo ("</td>"); echo ("<td>"); echo ($row["sport"]); echo ("</td>"); echo ("<td>"); echo ($row["first_name"]); echo ("</td>"); echo ("<td>"); echo ($row["last_name"]); echo ("</td></tr>"); } echo "</tr></table>"; mysql_close($conn); ?> I think the problem is either with this part in the AJAX Code: [Select] xmlhttp.open("GET","Query.php?category_id="+str,true); or most likely in my Query.php code when I wasn't using AJAX and using POST it worked fine, but adding the AJAX stuff and GET it doesn't work. When I echo out the SQL the result is Code: [Select] SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.category_id = '' so the category_id is not being selected properly and that is the primary key/foreign key in the MySQL table which connects the JOIN. I have a odd one here, two classes and one which calls another class. I want to pass all of the parameters from the array as seperate variables into the next function. Hope my example explains a little better class master{ public function __call($name, $args) { second->$name($args); }}class second{ public function example($param1, $param2) { }}master->example($param1, $param2);() ( i know its not accurate php, but should get the idea of what im trying to do) I need to do something with the following line second->$name($args); Where param1 and param2 will be seperated out Is there a php function which you can tell it the class, method name and pass it an array of parameters? Thanks Hello I've have read that global variables should not be used. so if i have 2 .php files: index.php - main content php file sitefunctions.php - php functions site file on my index.php page i have the following (an example of my problem): <?php displayError($errorID); ?> and in the sitefunctions.php file i have the following (an example of my problem): <?php function displayError($errorID) { if($errorID == 1) { echo "Password Failure"; } else { echo "Other Failure"; } } ?> now that works but since when first accesing that page the $errorID is not set then i get an error. How can i achieve this without first setting a blank $errorID global variable? Thanks I need someone to explain how to loop through an array ($products) and grab the three values (name, price, & shipping) and have them sent to "all_products" function - see line 13 then 61 thru 64. I currently have the script partially working by using array_shift which I know is removing the 1st element (name or $product value). Note: this is the problem (I need $product included in the call to the "all_products" function along with $price & $shipping so that the final output looks as follow: --------------------------------- Checkout Below is a summary of the products you wish to purchase, along with totals: * Candle Holder: $12.95 * Coffee Table: $99.5 * Lamp: $42.99 Total (including tax and shipping): $182.12 ------------------------------------------------------ HERE'S THE SCRIPT FOR REVIEW & COMMENT: =============================== <B>Checkout</B><br> Below is a summary of the products you wish to purchase, along with totals: <?php /* Fix this code by creating a function to determine sub-totals for each product. Then add the sub-totals together to arrive at the grand total.The product name, & price should display for each item. ?><ul><? /* "all_products" function was created to query then calculate the sub-totals for each prodcut, then add each sub-total togehter to form grand total - outside the function */ function all_products($prod_array) { extract($prod_array); #tax rate is constant $tax = 0.08; $total_price = 0; $total_tax = 0; $total_shipping = 0; // Calculations per product with returned sum sent outside to $grand_total variable $total_price += $price; $total_tax += $tax * $price; $total_shipping += $shipping * $price; $sub_total = ($total_price + $total_tax + $total_shipping); # This calculates the sub-total (or Grand total) for each product echo "<li>".$product.": $".$price."<br />"; # THE PRODUCT NAME & PRICE SHOULD DISPLAY HERE (NAME IS NOT SHOWING WHICH IS PROBLEM) # I had echo statement to confirm calculation on product was correct # echo "Grand Total is $".$sub_total."<br />"; return $sub_total; # This breaks out of the function when Candle Holder IF statement is true; returning value } /* Keep the functions, and add a two-dimensional array that acts as a product database -- it should contain the name, price, and shipping price for every product -- and use list() and each() to traverse the database. */ // Products array with List / Each configuration to pass arguements into function $products = array('Candle Holder' => array('price' => '12.95','shipping' => '0.00'), 'Coffee Table'=>array('price' => '99.50','shipping' => '0.10'), 'lamp' =>array('price' => '99.50','shipping' => '0.10')); while (list($k, $v) = each($products)) { $product = $k; # This is individual product name extracted from array #echo "Here's the price & shipping cost for ".$product.":<br/>"; while (list($key, $value) = each($v)) { if (array_key_exists('price',$v)) { $price = $value; #echo "The product ".$key." is: $".$value."<br />"; } if (array_key_exists('shipping',$v)) { $shipping = $value; #echo "The ".$key." cost is: ".$value."<br />"; } } } # THE BELOW THREEE LINES TRAVERSE THE ARRAY BUT STRIPPING THE 1ST ELEMENT WHICH IS NOT WHAT I WANT; I NEED THE INCLUDED TO DISPLRAY BEFORE PRICES $sub_total1 = all_products(array_shift($products)); $sub_total2 = all_products(array_shift($products)); $sub_total3 = all_products(array_shift($products)); echo "RESULTS OUTSIDE FUNCTION: ".$sub_total1."<br />"; echo "RESULTS OUTSIDE FUNCTION: ".$sub_total2."<br />"; echo "RESULTS OUTSIDE FUNCTION: ".$sub_total3."<br />"; // Add total sum for each product to define grand total for all products including shipping & taxes $grand_total = $sub_total1 + $sub_total2 + $sub_total3; ?> </ul> <hr> <br> <?php # Below is the "GRAND TOTAL" for all three project - displayed outside the function which should be $182.12 USD ?> <B>Total (including tax and shipping): $<? echo number_format($grand_total, 2); ?></B> This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=315384.0 Hello, I was trying out some code to check out how some of the php settings work and when i tried allow_call_time_pass_reference to see if it works, it doesn't spew out any warning or error like the comments in the .ini file mention (or in the manual sites). Maybe i'm not using some other setting in order to see this? Here is my EXACT code. <?php ini_set('display_errors',1); error_reporting(-1); $variable = 'String'; function display($variable) { return $variable; } echo display(&$variable); ?> Outputs : String. No errors, no warnings. I'm running PHP Version 5.3.2-1ubuntu4.5 Hello forum,
So I've been developing an app mostly in PHP, but am rather afraid of JS. Hope to fix that.
I have an AJAX dropdown using JQuery to search locations. It works great. However, I want to make it similar to what is seen on this site:
http://placefinder.com/
As you can see, the dropdown, when clicked populates a box. Then the user submits the form and the data is used in the application.
I have no clue how to make the form populate with data from the DB (I'm using mySQL) when clicked. So far, I've only been able to make it clickable as a URL (not what I want, obvioiusly!)
Is there a way to do this on a really small, simple script for starters? I'm certain their is, but don't even know where to begin.
Any help appreciated
There are two pieces to this- The HTML Form and the resulting php. I can't seem to make the leap, from the code to having the form produce the php page so others can view it until the form is again submitted overwriting the php, thus generating new content. The environment I am working in is limited to IIs 5.1 and php 5.2.17 without mySQL or other DB I'm new to php, this isn't homework,or commercialization, it's for children. I am thinking perhaps fwrite / fread but can't get my head around it. Code snipets below. Any help, please use portions of this code in hopes I can understand it Thanks Code snipet from Output.php Code: [Select] <?php $t1image = $_POST["t1image"]; $t1title = $_POST["t1title"]; $t1info = $_POST["t1info"]; $t2image = $_POST["t2image"]; $t2title = $_POST["t2title"]; $t2info = $_POST["t2info"]; ?> ... <tbody> <tr><!--Headers--> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Animal</td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Image thumb<br> </td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Date<br> </td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Information<br> </td> </tr> <tr> <td style="vertical-align: top; text-align: center;">Monkey </td> <td style="vertical-align: top; text-align: center;"><img src="<?php echo $t1image.'.gif'; ?>"><!--single image presented selected from radio buttons--> </td> <td style="vertical-align: top; text-align: center;"><?php echo date("m/d/Yh:i A"); ?><!--time stamp generated when submitted form populates all fields at once--> </td> <td style="vertical-align: top; text-align: center;"><a href="#monkey" rel="facebox"><?php echo $t1title ?></a><!--Link name provided by "Title 1", that links to hidden Div generated page with content from "Info1" field--> <div id="Monkey" style="display:none"> <?php echo $t1info; ?> </div> </td> </tr> <tr> <td style="vertical-align: top; text-align: center;">Cat<br> </td> <td style="vertical-align: top; text-align: center;"><img src="<?php echo $t2image.'.gif'?>"></td> <td style="vertical-align: top; text-align: center;"><?php echo date("m/d/Yh:i A"); ?></td> <td style="vertical-align: top; text-align: center;"><a href="#Cat" rel="facebox"><?php echo $t2title ?></a> <div id="Cat" style="display:none"> <?php echo $t2info; ?> </div> </td> </tr> <tr> This replicates several times down the page around 15-20 times ( t1### - t20###) Code Snipet from HTML Form Code: [Select] <form action="animals.php" method="post"> <div style="text-align: left;"><big style="font-family: Garamond; font-weight: bold; color: rgb(51, 51, 255);"><big><big><span>Monkey</span></big></big></big><br> <table style="text-align: left; width: 110px;" border="0" cellpadding="2" cellspacing="0"> <tbody><tr> <td style="vertical-align: top;">Image thumb<br> <input type="radio" name="t1image" value="No opinion" checked><img src="eh.gif" alt="Eh"> <input type="radio" name="t1image" value="Ok"><img src="ok.gif" alt="ok"> <input type="radio" name="t1image" value="Like"><img src="like.gif" alt="Like"> <input type="radio" name="t1image" value="Dont"><img src="dont.gif" alt="Don't Like"> <input type="radio" name="t1image" value="Hate"><img src="hate.gif" alt="Hate"> <input type="radio" name="t1image" value="Other"><img src="other.gif" alt="Other"> <br> Why Title:<input type="text" name="t1title" size="45" value="..."/></td> <td style="vertical-align: top;"> Explain:<br> <textarea name="t1info" cols=45 rows=3 value="..."></textarea> </td></tr></table> <br> <!--Next--> How do I get the Form data to save to the php page for others to view? Hi all, I have an html form that sends formdata to a php script called example.php with the POST method. example.php then has the following structu Code: [Select] <?php if(isset($_POST['var1'])) {$var1 = $_POST['var1'];} else {$var1 = 'English';} if(isset($_POST['var2'])) {$var2 = $_POST['var2'];} else {$var2 = 'French';} print" <html> <body> <form> <select id='select1'> <option>var1</option> <option>var2</option> <option>etc...</option> </select> <input type='text' id='input1'> ETC. ETC. </form> </body> </html> "; ?> So example.php has an embedded html form. How do I specify that some elements of the form should take their values from the variables retrieved at the start of the script via the POST command? For example, I want select1 to have 'var1' pre-selected and I want input1 to display var2. var1 & var2 get sent through to example.php fine, I just don't know how to get the embedded html form to use them. Please help! Thanks a lot. Hello, I've been trying this for hours now, looking at different examples and trying to change them to work for me, but with no luck... This is what I am trying to do: I have a simple form with: - 1 input field, where I can enter a number - 1 Submit Button When I enter a number into the field and click submit, I want that number to be send to the php file that is in the ajax call, then the script will take that number and run a bunch of queries and then return a new number. I want that new number to be used to call the php script via ajax again, until no number is returned, or something else is returned like the word "done" or something like that, at which point is simply makes an alert or populated a div with a message... The point is, that depending on the number entered it could take up to an hour to complete ALL the queries, so I want the script that is called to only run a fixed amount of queries at a time and then return the number it is currently at (+1), so that it can continue with the next number when it is called again. I would like to use jquery, but could also be any other way, as long as I get this to work. I already have the php script completed that needs to be called by the ajax, it returns a single number when being called. Thank you, vb This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319071.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=308349.0 I am getting this error in the header.php of my wordpress theme... Can anyone help? Thanks! Warning: implode() [function.implode]: Invalid arguments passed in /home/bexxx/public_html/wp-content/themes/organic_portfolio_gray/header.php on line 74 <!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" <?php language_attributes(); ?>> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <meta name="distribution" content="global" /> <meta name="robots" content="follow, all" /> <meta name="language" content="en" /> <title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' :'; } ?> <?php bloginfo('name'); ?></title> <link rel="Shortcut Icon" href="<?php echo bloginfo('template_url'); ?>/images/favicon.ico" type="image/x-icon" /> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" /> <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" /> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?> <?php wp_enqueue_script("jquery"); ?> <?php wp_head(); ?> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/superfish/superfish.js"></script> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/superfish/hoverIntent.js"></script> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.flow.1.1.js"></script> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/iepngfix_tilebg.js"></script> <!--IE6 Fix--> <style type="text/css"> img, div, a, input, body, span { behavior: url(<?php bloginfo('template_url'); ?>/images/iepngfix.htc); } </style> <script type="text/javascript"> var $j = jQuery.noConflict(); $j(function() { $j("div#controller").jFlow({ slides: "#slides", width: "960px", height: "480px", timer: <?php echo ot_option('slider_interval'); ?>, duration: 400 }); }); </script> <script type="text/javascript"> $j(document).ready(function() { $j('ul.ot-menu').superfish(); }); </script> </head> <body> <div id="wrap"> <div id="header"> <div class="headercenter"> <p id="title"><a href="<?php echo get_option('home'); ?>/" title="Home"><?php bloginfo('name'); ?></a></p> </div> </div> <div id="navbar"> <div id="nav"> <div id="navbarleft"> <ul class="ot-menu"><li<?php if (is_home()) { echo " class=\"current_page_item\""; }?>><a href="<?php echo get_settings('home'); ?>"><?php _e("Home", 'organicthemes'); ?></a></li> <?php $include_categories = ot_option('include_categories'); ?> <?php wp_list_categories('depth=4&title_li=&sort_column=menu_order&include='.implode(',', $include_categories)); ?></ul> </div> <div id="navbarright"> <ul class="ot-menu"> <?php $include_pages = ot_option('include_pages'); ?> <?php wp_list_pages('title_li=&sort_column=menu_order&include='.implode(',', $include_pages)); ?> </ul> </div> </div> </div> <div style="clear:both;"></div> i have a problem i cant solved for cople of hours! this is the function: function show_posts($user_id,$limit=0){ $posts = array(); $user_string = implode(',', $user_id); $extra = " and id in ($user_string) "; if ($limit > 0){ $extra = "limit $limit"; }else{ $extra = ''; } $sql = "SELECT userid, caption, stamp, filename FROM photographs WHERE userid in ($user_string) order by stamp desc $extra"; //echo $sql; $result = mysql_query($sql) or die(mysql_error()) ; while($data = mysql_fetch_object($result)){ $posts[] = array( 'stamp' => $data->stamp, 'userid' => $data->userid, 'caption' => $data->caption, 'filename' => $data->filename, ); } return $posts; } and thats the full error: Warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\includes\functions.php on line 12 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') order by stamp desc' at line 2 and the intresting thing that if i echo the sql i get a working one i checked it in phpmyadmin + it shows what it need to show in the index.php if i comment the "or die(mysql_error()) " here the sql when its do echo SELECT userid, caption, stamp, filename FROM photographs WHERE userid in (4,7,2) order by stamp desc limit 5 so y the hell this problem is keep coming? i really cant understand what wrong! tnx for the help! I am using a PHP class (it is attached) for Google Analytics that I got from this link below: http://www.acleon.co.uk/?p=173 Unfortunately, it appears the Class has a PHP error: Warning: implode() [function.implode]: Invalid arguments passed in Galvanize.php on line 114 and line 181. This is line 114: setcookie('__utmc', implode('.', $this->UTMC), 0, $this->CookiePath, $this->getDomain()); Here is line 181: $urchinUrl .= '&utmcc=__utma%3D'.implode('.', $this->UTMA).'%3B%2B__utmz%3D'.implode('.', $this->UTMZ).'%3B'; I did not see UTMC and UTMZ declared anywhere in the Class. The class file is attached. Thanks for your help in advance. Hello, I'm just a beginner (and french sorry for my language) : have some pb with my little implode function. It's Running well on my local webserver (MAMP - PHP PHP Version 5.2.17) but when tested on ovh server (PHP4) show this error : Warning: implode() [function.implode]: Invalid arguments passed in /homez.xx/myPathHere/entete.php5 on line 6 I understand 1/ that one argument is missing but don't find the right syntax 2/ I have tried to turn this file on php5 with this extension (ovh is under php4) Here is my code in page defining the value and where stay my query (entete.php5) <?php if (isset($theme)) { $t = implode(',',$theme); $lien = "aide.php5?theme=".$t; $aide = '<a href="'.$lien.'">'.$onglet[0].'</a>'; } else { $aide = ""; } ?> Here is my code in page which show result (aide.php5) $t = explode(',',$_GET['theme']); $n = count($t); if ($n == 1) { $where = "id = ".$t[0]; } else { $where = "id = ".$t[0]; for ($i=1;$i<$n;$i++) { $where .= " OR id=".$t[$i]; } } Hope someone kindly help me : thanks in advance My error is 'Warning: implode() [function.implode]: Invalid arguments passed in /home/definiti/public_html/contact.php on line 73' Im not sure how to fix this error, as I looked online and it says that my implode() has the right layout too it.. Line 73 in my code (I took the HTML code out) is this line; Code: [Select] $message = implode("<br>\n", $messages); My whole code is; Code: [Select] <?php # PHP Copyright 2007, Thomas Boutell and Boutell.Com, Inc. # Edited by Definition Designs. $recipient = 'defenitiondesigns@googlemail.com'; $serverName = 'www.definition-designs.co.uk'; if ($_POST['send']) { sendMail(); } elseif (($_POST['cancel']) || ($_POST['continue'])) { redirect(); } else { displayForm(false); } function displayForm($messages) { global $login; $escapedEmail = htmlspecialchars($_POST['email']); $escapedRealName = htmlspecialchars($_POST['realname']); $escapedSubject = htmlspecialchars($_POST['subject']); $escapedBody = htmlspecialchars($_POST['body']); $returnUrl = $_POST['returnurl']; if (!strlen($returnUrl)) { $returnUrl = $_SERVER['HTTP_REFERER']; if (!strlen($returnUrl)) { $returnUrl = '/'; } } $escapedReturnUrl = htmlspecialchars($returnUrl); ?> <?php if (count($messages) > 0) { $message = implode("<br>\n", $messages); echo("<h4>$message</h4>\n"); } ?> <form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>"> <p> <b>Your</b> Email Address <input name="email" size="35" maxlength="35" value="<?php echo $escapedEmail?>"/> </p> <p> Your <b>Real</b> Name <input name="realname" size="35" maxlength="35" value="<?php echo $escapedRealName?>"/> </p> <p> Subject Of Your Message <input name="subject" size="35" maxlength="35" value="<?php echo $escapedSubject?>"/> </p> <p> <i>Please enter the text of your message in the field that follows.</i> </p> <textarea name="body" rows="10" cols="60"><?php echo $escapedBody?></textarea> <p> <input type="submit" name="send" value="Send Your Message"/> <input type="submit" name="cancel" value="Cancel - Never Mind"/> </p> <input type="hidden" name="returnurl" value="<?php echo $escapedReturnUrl?>"/> </form> <?php } function redirect() { global $serverName; $returnUrl = $_POST['returnurl']; $prefix = "http://$serverName/"; if (!beginsWith($returnUrl, $prefix)) { $returnUrl = "http://$serverName/"; } header("Location: $returnUrl"); } function beginsWith($s, $prefix) { return (substr($s, 0, strlen($prefix)) === $prefix); } function sendMail() { global $recipient; $messages = array(); $email = $_POST['email']; if (!preg_match("/^[\w\+\-\.\~]+\@[\-\w\.\!]+$/", $email)) { $messages[] = "That is not a valid email address. In format: You@something.com"; } $realName = $_POST['realname']; if (!preg_match("/^[\w\ \+\-\'\"]+$/", $realName)) { $messages[] = "The real name field must contain only alphanumeric characters, spaces and + or - signs."; } $subject = $_POST['subject']; if (preg_match('/^\s*$/', $subject)) { $messages[] = "Please specify a subject for your message. "; } $body = $_POST['body']; if (preg_match('/^\s*$/', $body)) { $messages[] = "Your message was blank. Fill out a message or Click Cancel to cancel message."; } if (count($messages)) { displayForm($messages); return; } mail($recipient, $subject, $body) or die("unable to send the mail!"); $escapedReturnUrl = htmlspecialchars($_POST['returnurl']); ?> <form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>"> <input type="submit" name="continue" value="Click Here To Continue"/> <input type="hidden" name="returnurl" value="<?php echo $escapedReturnUrl?>"/> </form> <?php } ?> I am learning how to use PHP to handle input in a Contact Form on my website. Using PHP I can send the form data to my email client. However I cannot achieve the outcome of sending a copy to the email address of the submitter. I have searched the Internet particularly Stack Overflow and have found code that I am told will achieve this outcome Here is the code: <?php if(isset($_POST['submit'])){ $to = "email@example.com"; // this is your Email address $from = $_POST['email']; // this is the sender's Email address $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $subject = "Form submission"; $subject2 = "Copy of your form submission"; $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message']; $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message']; $headers = "From:" . $from; $headers2 = "From:" . $to; mail($to,$subject,$message,$headers); mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender // echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly."; OR // You can also use header('Location: thank_you.php'); to redirect to another page. } ?> Adjusting it for my own circumstances and settings it will still send the information in the form to me but will not send the information to the submitter's email address. What is particularly confusing is, if I modify the code by taking out this line of code mail($to,$subject,$message,$headers); Which includes my email address ($to), it still works and the information including ($subject) is still sent to my email address. I would appreciate any assistance that anyone would offer been messing with this for half a hour cant find the right format for adding this $_GET in the action part of this form Code: [Select] <?php echo '<form name="newmessage" method="post" action='"send_message.php?goauld=".($_GET['goauld'])."";? > I have looked up tutorials on Google. I am still confused. I built a php script that receives the data from my html form then filters out bad words. I am trying to get the script to resend the data to pm.cgi. The form was originally targeting pm.cgi but it needed filtered. This is why i am using php in the first place. Please help me pass these variables from the php script to the cgi script the same way that a html form would. Thank you. Here is my code, it prints correctly. I cannot get cURL to work. <?php $action = $_GET['action'] ; $login = $_REQUEST['login'] ; $ID = $_REQUEST['ID'] ; $text = $_REQUEST['Unused10'] ; $submit = $_REQUEST['submit'] ; function filterBadWords($str){ // words to filter $badwords=array( "badword1", "badword2"); // replace filtered words with random spaces $replacements=array( "****", "***", "****" ); for($i=0;$i < sizeof($badwords);$i++){ srand((double)microtime()*1000000); $rand_key = (rand()%sizeof($replacements)); $str=eregi_replace($badwords[$i], $replacements[$rand_key], $str); } return $str; } $text = filterBadWords($text); print_r($action); print_r($login); print_r($ID); print_r($text); print_r($submit); ?> I need to send the variables that i printed above to pm.cgi. Can you point me in the right direction? Thanks again! |