PHP - Creating A Receipt Form (converting Numbers)
Hello, I need to create a receipt using php/SQL:
I know how to do it but I have a question please: ... Name: ______________ Amount: ______________ Signatu _____________ If I put the amount: $200 how can it be typed Two Hundred or if I type: $150 can It be typed One hundred fifty? Thanks a lot... Similar TutorialsHello. This is my first post here. I am not an expert developer but I generally manage to do what is asked of me. However, now and then I'm stumped, like now... I have an online database system for our company in which staff can enter JOB related data, this includes 2 dimensions which they enter in millimetres (mm). Here's an example
$dimension1 might be entered as 850 Firstly, I need to round both dimensions up to the next 100mm so the 850 in this example would become 900 and the 1447 would become 1500. Once I've done that, I need to calculate the square metres (900mm x 1500mm / 1000 was my first thought) but that raised the second thing; adding a decimal point in the result. 900 x 1500 / 1000 = 1350 but I need the result to be 1.350 I know my way around basic PHP code but I'm no expert by any stretch. If anyone can help me understand how to get this calculation done I would be hugely appreciative. Thank you Martin I am working on convering an old PHP form mail script to do error checking on the same page as the form rather then using redirects and I am having a bit of trouble with the logic. Right now it seems to work okay in general, but will send blank emails without doing the error check. Can someone please help me get it sorted out so that it works correctly. Also any ideas or input on how to make it more secure are appreciated. Thanks in advance, kaiman Here is the section of code in question: Code: [Select] // validate form if(isset($_POST['submit'])){ // check for empty form fields if (empty($name) || empty($email) || empty($category) || empty($formsubject) || empty($message)) { echo "<p>Please complete all required form fields.</p>"; } // sanitize and validate email address $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL) ; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "<p>Please enter a valid email address.</p>"; } // check for special characters in the message field and reformat if (get_magic_quotes_gpc()) { $message = stripslashes($message); } } if(isset($_POST['email'])){ // if valid send email mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\r\n" . "Reply-To: \"$name\" <$email>\n" . "X-Mailer: PHP 5.2.5" ); header( "Location: $successurl" ); } else { echo "<!-- begin form -->\n"; echo "<form name=\"Contact\" class=\"contentform\" method=\"post\" action=\"" . $_SERVER['REQUEST_URI'] . "\">\n"; echo "<fieldset>\n"; echo "<legend>Contact Form</legend>\n"; echo "<ol class=\"form\">\n"; echo "<li class=\"formleft\">\n"; echo "<label for=\"name\"><span class=\"asterisk\">*</span> Your Name:</label>\n"; echo "<input class=\"textfield\" id=\"name\" name=\"name\" type=\"text\" value=\"\" />\n"; echo "</li>\n"; echo "<li class=\"formright\">\n"; echo "<label for=\"email\"><span class=\"asterisk\">*</span> Email Address:</label>\n"; echo "<input class=\"textfield\" name=\"email\" type=\"text\" id=\"email\" value=\"\" />\n"; echo "</li>\n"; echo "<li class=\"formleft\">\n"; echo "<label for=\"category\"><span class=\"asterisk\">*</span> Form Category:</label>\n"; echo "<select class=\"select\" name=\"category\" id=\"category\" onchange=\"javascript:enableOther();\">\n"; echo "<option value=\"\">Please Select an Option:</option>\n"; echo "<option value=\"Question\" >Question</option>\n"; echo "<option value=\"Comment\" >Comment</option>\n"; echo "<option value=\"Idea\">Idea</option>\n"; echo "<option value=\"Other\">Other</option>\n"; echo "</select>\n"; echo "</li>\n"; echo "<li class=\"formright\">\n"; echo "<label for=\"formsubject\"><span class=\"asterisk\">*</span> Form Subject:</label>\n"; echo "<input class=\"textfield\" name=\"formsubject\" type=\"text\" id=\"formsubject\" value=\"\" />\n"; echo "</li>\n"; echo "<li>\n"; echo "<label for=\"message\"><span class=\"asterisk\">*</span> Your Message:</label>\n"; echo "<textarea name=\"message\" class=\"textarea\" rows=\"5\" cols=\"20\" id=\"message\" value=\"\"></textarea>\n"; echo "</li>\n"; echo "<li>\n"; echo "<label for=\"submitbutton\"></label>\n"; echo "<button class=\"submitbutton\" type=\"submit\" name=\"submit\" title=\"Submit\">Submit</button>\n"; echo "</li>\n"; echo "</ol>\n"; echo "</fieldset>\n"; echo "</form>\n"; echo "<!-- end form -->\n"; } Hi, I'm new to PHP and have dabbled a little but need some help or someone to point me in the right direction if possible. I have an ajax web-form that sends the inputed data to a php file and then emails the results to the designated address (all working fine). However, what I am looking to do is have the php file (in addition to the current function) convert the data into XML and then attach the XML file to the email that is sent out. As mentioned I'm new to php and have a small amount of knowledge so any help on this would be very much appreciated. Cheers Hey people, First post but i have visited for a while. I have the following HTML form which basically submits the $_session stored variables to PayPal. Advantage being that the user then doesn't need to re-enter their personal info at paypal. Code: [Select] <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_ext-enter"> <input type="hidden" name="redirect_cmd" value="_xclick"> <input type="hidden" name="business" value="myemailaddress@business.com"> <input type="hidden" name="item_name" value="myitem"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<? echo $_SESSION['price']; ?>"> <input type="hidden" name="email" value="<? echo $_SESSION['email']; ?>"> <input type="hidden" name="first_name" value="<? echo $_SESSION['fname']; ?>"> <!--the rest of my fields --> <input type="hidden" name="currency_ code" value="GBP"> <input type="hidden" name="country" value="GB"> <input type="submit" class="buybtn" value=""> </form> Problem is i need to also submit some data to a database when the buy button is clicked and i cant have a form with two actions - therefore i need to change from what i have above to the form action being "paypal.php". That paypal.php script needs to do 2 things: 1) submit some data to my mysql database (that part i can do) and 2) submitting some &_session data to the paypal url (https://www.paypal.com/cgi-bin/webscr) just the same as the HTML form does...and take the user to that url...how do i do this? lol. I have no idea where to start in converting the below portion of the above form into a php code that a) submits to a url and (rather than a database) and b) redirects the user to that same url: Code: [Select] <input type="hidden" name="cmd" value="_ext-enter"> <input type="hidden" name="redirect_cmd" value="_xclick"> <input type="hidden" name="business" value="myemailaddress@business.com"> <input type="hidden" name="item_name" value="myitem"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<? echo $_SESSION['price']; ?>"> <input type="hidden" name="email" value="<? echo $_SESSION['email']; ?>"> <input type="hidden" name="first_name" value="<? echo $_SESSION['fname']; ?>"> <!--the rest of my fields --> <input type="hidden" name="currency_ code" value="GBP"> <input type="hidden" name="country" value="GB"> Any help anyone can give me will be massively appreciated! Thanks everyone, Bill. I want a guidance to help me in setting up the mike42/escpos-php library with online POS website without printer can any one help me to solve the issue in php. I have Point of sale website in online server. I connect the print recipt code which is in my local server with this point of sale. but print is not working. I used the mike42/escpos-php library from github https://github.com/mike42/escpos-php. The following errors occoured whrn i click on print button. 1: Warning: copy(\\DESKTOP-L48VCRS\EPSON TM-U220 CAJA): failed to open stream: No such file or directory in C:\wamp64\www\sistema\src\Mike42\Escpos\PrintConnectors\WindowsPrintConnector.php on line 372 2: Fatal error: Uncaught Exception: Failed to copy file to printer in C:\wamp64\www\sistema\src\Mike42\Escpos\PrintConnectors\WindowsPrintConnector.php on line 291 3: Exception: Failed to copy file to printer in C:\wamp64\www\sistema\src\Mike42\Escpos\PrintConnectors\WindowsPrintConnector.php on line 291 The online website or POS url is http://dfathers.es Please any one help me to solve the issues. thanks I am trying to print an image to a thermal POS printer from a PHP script. I have managed to get a text file to print by saving it to a file and copying to the USB port and that works fine. Am running PHP on Windows. Would appreciate any assistance. Thanks Steve I recently changed the PHP code where the submitter receives a receipt, Now they want the submitter to receive it with less fields than what the E-mail goes to.
For example the people who get the email from the submitter sees all the fields, but the submitter gets a receipt with different fields. I cannot seem to figure it out. Any help is appreciated. So I receive all this fields name,lastname,email,Phone,ReferredBy. But the submitter receives only these files name,lastname,ReferredBy
<?php // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! $yourEmail = "example1@email,example2@email.com"; // the email address you wish to receive these mails through $yourWebsite = "Application"; // the name of your website $thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4 $requiredFields = "name,lastname,email,Phone,ReferredBy"; // names of the fields you'd like to be required as a minimum, separate each field with a comma $textlink ='<a href="confirmation.html">Click Here And Take The Next Step</a>.' ; // DO NOT EDIT BELOW HERE $error_msg = array(); $result = null; $requiredFields = explode(",", $requiredFields); function clean($data) { $data = trim(stripslashes(strip_tags($data))); return $data; } function isBot() { $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz"); foreach ($bots as $bot) if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false) return true; if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ") return true; return false; } if ($_SERVER['REQUEST_METHOD'] == "POST") { if (isBot() !== false) $error_msg[] = "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT']; // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score.. // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam $points = (int)0; $badwords = array("adult"); foreach ($badwords as $word) if ( strpos(strtolower($_POST['comments']), $word) !== false || strpos(strtolower($_POST['name']), $word) !== false ) $points += 2; if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false) $points += 2; if (isset($_POST['nojs'])) $points += 1; if (preg_match("/(<.*>)/i", $_POST['comments'])) $points += 2; if (strlen($_POST['name']) < 3) $points += 1; if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500)) $points += 2; if (preg_match("/[bcdfghjklmnpqrstvwxyz]{7,}/i", $_POST['comments'])) $points += 1; // end score assignments foreach($requiredFields as $field) { trim($_POST[$field]); if (!isset($_POST[$field]) || empty($_POST[$field]) && array_pop($error_msg) != "Please fill in all the required fields and submit again.\r\n") $error_msg[] = "Please fill in all the required fields and submit again."; } if (!empty($_POST['name']) && !preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) $error_msg[] = "The name field must not contain special characters.\r\n"; if (!empty($_POST['email']) && !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) $error_msg[] = "That is not a valid e-mail address.\r\n"; if ($error_msg == NULL && $points <= $maxPoints) { $subject = "Payment"; $message = "New applicant: \n\n"; foreach ($_POST as $key => $val) { if (is_array($val)) { foreach ($val as $subval) { $message .= ucwords($key) . ": " . clean($subval) . "\r\n"; } } else { $message .= ucwords($key) . ": " . clean($val) . "\r\n"; } } $message .= "\r\n"; // this means reply to the sender with e-mail and subject. if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { $headers = "From: {$_POST['email']}\r\n"; $headers .= "Bcc: $yourEmail\r\n"; $headers .= "Reply-To: {$_POST['email']}\r\n"; } else { $headers = "From: {$_POST['email']}\r\n"; $headers .= "Bcc: $yourEmail\r\n"; $headers .= "Reply-To: {$_POST['email']}\r\n"; } if (mail($_POST['email'],$subject,$message,$headers)) { if (!empty($thanksPage)) { header("Location: $thanksPage"); exit; } else { $result = 'Congratulations! We have received your application. IMPORTANT Click link below'; $disable = true; } } else { $error_msg[] = 'Your mail could not be sent this time. ['.$points.']'; } } else { if (empty($error_msg)) $error_msg[] = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']'; } } function get_data($var) { if (isset($_POST[$var])) echo htmlspecialchars($_POST[$var]); } ?> I'm trying to show on my order printed receipt some checkout fields and extras from the products. The website is www.prontoitaliano.co.uk/shop What needs to appear on the receipt are all the extras options from all the products(See checkboxes in all pasta dishes and checkboxes toppings in "create your own pizza") and 2 fields from the checkout page (Pick up Date, Pick up Time). To send the order to the printer I'm using the "Star cloud PRNT woocommerce" plugin and for the pickup date and time fields "ultimate woocommerce delivery and pickup date time", I've attached below the code that needs to be edited to add more fields to the receipt. I know that probably it's not difficult to solve my issue but I don't have any knowledge of php and I hope you guys can assist me. Also, I've attached a picture showing what is missing on the printed receipt and what result I'm trying to get. Thanks for your time!
<?php function star_cloudprnt_get_column_separated_data($columns) { $max_chars = STAR_CLOUDPRNT_MAX_CHARACTERS_THREE_INCH; $total_columns = count($columns); if ($total_columns == 0) return ""; if ($total_columns == 1) return $columns[0]; if ($total_columns == 2) { $total_characters = strlen($columns[0])+strlen($columns[1]); $total_whitespace = $max_chars - $total_characters; if ($total_whitespace < 0) return ""; return $columns[0].str_repeat(" ", $total_whitespace).$columns[1]; } $total_characters = 0; foreach ($columns as $column) { $total_characters += strlen($column); } $total_whitespace = $max_chars - $total_characters; if ($total_whitespace < 0) return ""; $total_spaces = $total_columns-1; $space_width = floor($total_whitespace / $total_spaces); $result = $columns[0].str_repeat(" ", $space_width); for ($i = 1; $i < ($total_columns-1); $i++) { $result .= $columns[$i].str_repeat(" ", $space_width); } $result .= $columns[$total_columns-1]; return $result; } function star_cloudprnt_get_seperator() { $max_chars = STAR_CLOUDPRNT_MAX_CHARACTERS_THREE_INCH; return str_repeat('_', $max_chars); } function star_cloudprnt_parse_order_status($status) { if ($status === 'wc-pending') return 'Pending Payment'; else if ($status === 'wc-processing') return 'Processing'; else if ($status === 'wc-on-hold') return 'On Hold'; else if ($status === 'wc-completed') return 'Completed'; else if ($status === 'wc-cancelled') return 'Cancelled'; else if ($status === 'wc-refunded') return 'Refunded'; else if ($status === 'wc-failed') return 'Failed'; else return "Unknown"; } function star_cloudprnt_get_codepage_1252_currency_symbol() { $symbol = get_woocommerce_currency_symbol(); if ($symbol === "£") return "\xA3"; // £ pound else if ($symbol === "$") return "\x24"; // $ dollar else if ($symbol === "€") return "\x80"; // € euro return ""; // return blank by default } function star_cloudprnt_get_formatted_variation($variation, $order, $item_id) { $return = ''; if (is_array($variation)) { $variation_list = array(); foreach ($variation as $name => $value) { // If the value is missing, get the value from the item if (!$value) { $meta_name = esc_attr(str_replace('attribute_', '', $name)); $value = $order->get_item_meta($item_id, $meta_name, true); } // If this is a term slug, get the term's nice name if (taxonomy_exists(esc_attr(str_replace('attribute_', '', $name)))) { $term = get_term_by('slug', $value, esc_attr(str_replace('attribute_', '', $name))); if (!is_wp_error($term) && ! empty($term->name)) { $value = $term->name; } } else { $value = ucwords(str_replace( '-', ' ', $value )); } $variation_list[] = wc_attribute_label(str_replace('attribute_', '', $name)) . ': ' . rawurldecode($value); } $return .= implode('||', $variation_list); } return $return; } function star_cloudprnt_create_receipt_items($order, &$printer) { $order_items = $order->get_items(); foreach ($order_items as $item_id => $item_data) { $product_name = $item_data['name']; $product_id = $item_data['product_id']; $variation_id = $item_data['variation_id']; $item_qty = $order->get_item_meta($item_id, "_qty", true); $item_total_price = floatval($order->get_item_meta($item_id, "_line_total", true)) +floatval($order->get_item_meta($item_id, "_line_tax", true)); $item_price = floatval($item_total_price) / intval($item_qty); $currencyHex = star_cloudprnt_get_codepage_1252_currency_symbol(); $formatted_item_price = number_format($item_price, 2, '.', ''); $formatted_total_price = number_format($item_total_price, 2, '.', ''); $printer->set_text_emphasized(); $printer->add_text_line(str_replace('–', '-', $product_name)." - ID: ".$product_id.""); $printer->cancel_text_emphasized(); if ($variation_id != 0) { $product_variation = new WC_Product_Variation( $variation_id ); $variation_data = $product_variation->get_variation_attributes(); $variation_detail = star_cloudprnt_get_formatted_variation($variation_data, $order, $item_id); $exploded = explode("||", $variation_detail); foreach($exploded as $exploded_variation) { $printer->add_text_line(" ".ucwords($exploded_variation)); } } $printer->add_text_line(star_cloudprnt_get_column_separated_data(array(" Qty: ". $item_qty." x Cost: ".$currencyHex.$formatted_item_price, $currencyHex.$formatted_total_price))); } } function star_cloudprnt_create_address($order, $order_meta, &$printer) { $fname = $order_meta[_shipping_first_name][0]; $lname = $order_meta[_shipping_last_name][0]; $a1 = $order_meta[_shipping_address_1][0]; $a2 = $order_meta[_shipping_address_2][0]; $city = $order_meta[_shipping_city][0]; $state = $order_meta[_shipping_state][0]; $postcode = $order_meta[_shipping_postcode][0]; $tel = $order_meta[_billing_phone][0]; $printer->set_text_emphasized(); if ($a1 == '') { $printer->add_text_line("Billing Address:"); $printer->cancel_text_emphasized(); $fname = $order_meta[_billing_first_name][0]; $lname = $order_meta[_billing_last_name][0]; $a1 = $order_meta[_billing_address_1][0]; $a2 = $order_meta[_billing_address_2][0]; $city = $order_meta[_billing_city][0]; $state = $order_meta[_billing_state][0]; $postcode = $order_meta[_billing_postcode][0]; } else { $printer->add_text_line("Shipping Address:"); $printer->cancel_text_emphasized(); } $printer->add_text_line($fname." ".$lname); $printer->add_text_line($a1); if ($a2 != '') $printer->add_text_line($a2); if ($city != '') $printer->add_text_line($city); if ($state != '') $printer->add_text_line($state); if ($postcode != '') $printer->add_text_line($postcode); $printer->add_text_line("Tel: ".$tel); } function star_cloudprnt_print_order_summary($selectedPrinter, $file, $order_id) { $order = wc_get_order($order_id); $shipping_items = @array_shift($order->get_items('shipping')); $order_meta = get_post_meta($order_id); $printer = new Star_CloudPRNT_Star_Line_Mode_Job($selectedPrinter, $file); $printer->set_codepage("20"); // 20 hex == 32 decimal == 1252 Windows Latin-1 if (get_option('star-cloudprnt-print-logo-top-input')) $printer->add_nv_logo(esc_attr(get_option('star-cloudprnt-print-logo-top-input'))); $printer->set_text_emphasized(); $printer->set_text_center_align(); $printer->add_text_line("ORDER NOTIFICATION"); $printer->set_text_left_align(); $printer->cancel_text_emphasized(); $printer->add_new_line(1); $printer->add_text_line(star_cloudprnt_get_column_separated_data(array("Order #".$order_id, date("d-m-y H:i:s", time())))); $printer->add_new_line(1); $printer->add_text_line("Order Status: ".star_cloudprnt_parse_order_status($order->post->post_status)); $printer->add_text_line("Order Date: ".$order->order_date); if (isset($shipping_items['name'])) { $printer->add_new_line(1); $printer->add_text_line("Shipping Method: ".$shipping_items['name']); } $printer->add_text_line("Payment Method: ".$order_meta[_payment_method_title][0]); $printer->add_new_line(1); $printer->add_text_line(star_cloudprnt_get_column_separated_data(array('ITEM', 'TOTAL'))); $printer->add_text_line(star_cloudprnt_get_seperator()); star_cloudprnt_create_receipt_items($order, $printer); $printer->add_new_line(1); $printer->set_text_right_align(); $formatted_overall_total_price = number_format($order_meta[_order_total][0], 2, '.', ''); $printer->add_text_line("TOTAL ".star_cloudprnt_get_codepage_1252_currency_symbol().$formatted_overall_total_price); $printer->set_text_left_align(); $printer->add_new_line(1); $printer->add_text_line("All prices are inclusive of tax (if applicable)."); $printer->add_new_line(1); star_cloudprnt_create_address($order, $order_meta, $printer); $printer->add_new_line(1); $printer->set_text_emphasized(); $printer->add_text_line("Customer Provided Notes:"); $printer->cancel_text_emphasized(); $printer->add_text(empty($order->post->post_excerpt) ? "None" : $order->post->post_excerpt); if (get_option('star-cloudprnt-print-logo-bottom-input')) $printer->add_nv_logo(esc_attr(get_option('star-cloudprnt-print-logo-bottom-input'))); $printer->printjob(); } function star_cloudprnt_woo_on_thankyou($order_id) { $file = STAR_CLOUDPRNT_PRINTER_PENDING_SAVE_PATH.star_cloudprnt_get_os_path("/order_".$order_id."_".time().".bin"); $selectedPrinter = ""; $printerList = star_cloudprnt_get_printer_list(); if (!empty($printerList)) { foreach ($printerList as $printer) { if (get_option('star-cloudprnt-printer-select') == $printer['name']) { $selectedPrinter = $printer['printerMAC']; break; } } if ($selectedPrinter === "" && count($printerList) === 1) $selectedPrinter = $printer['printerMAC']; if ($selectedPrinter !== "") star_cloudprnt_print_order_summary($selectedPrinter, $file, $order_id); } } function star_cloudprnt_setup_order_handler() { if (selected(get_option('star-cloudprnt-select'), "enable", false) !== "" && star_cloudprnt_is_woo_activated()) { add_action('woocommerce_thankyou', 'star_cloudprnt_woo_on_thankyou', 1, 1); } }
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=353188.0 Hi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim hi i am not sure if i should be posting this problem hear.. so please direct me to the right place if i am. I am trying to create a application form, for people wanting to apply for a apartment. I managed to connect to the database set up table, even make the actual form. Know that everything is done i wanted to make it a little more interactive. I want the form to automatically show the price per month and the size of the apartment if the applicant choses apartment 1 on the form, or if he chooses apartment 2. a managed to tweak around with a filtering system by jquery but i am lost and tired, i wanted to know if there was something simple out there that could help me. Thank you so much for the help. this is what im looking to incorporate on my site
http://www.cpifl.org/signup.cfm
can someone help me get something like this up and running? or recommend a form i could download and edit....
thanks
trey
Hello guys,
I was just wondering what I was doing wrong here, I've 'created' a website form in PHP but when I click my submit button it doesn't seem to fetch:
php.php?s=1
or
php.php?s=2
which is then used to print either Success or Failure.
Here's my code:
<html> <head> <title></title> <meta charset="utf-8" /> <link rel="stylesheet" href="footer.css" type="text/css"/> <link rel="stylesheet" href="header.css" type="text/css"/> <link rel="stylesheet" href="php/phpbody.css" type="text/css"/> </head> <!--body--> <body> <div id="container"> <h3 id="h3">Contact Me:</h3> <?php $s = isset($_GET['s']) ? $_GET['s'] : ''; if ($s=="1") { echo ('<span class="success">Success! Your enquiry has been sent.</span>'); }else if ($s=="2"){ echo ('<span class="fail">Sorry! Your enquiry has not been sent. Please ensure you have filled in the form correctly.</span>'); } ?> <h5 id="h5">To contact me, please use this form, created with PHP:</h5> <form id="form1" name="form1" method="POST" action"php/send.php"> <strong>First Name:</strong><br><input type="text" name="firstname" id="firstname"><br><br> <strong>Last Name:</strong><br><input type="text" name="lastname" id="lastname"><br><br> <strong>E-mail:</strong><br><input type="text" name="email" id="email"><br><br> <strong>Enquiry:</strong><br><textarea name="enquiry" id="enquiry" cols="45" rows="5"></textarea><br><br> <strong>Security:</strong> 6 + 4 = <input type="text" name="security" id="security" size="1"><br><br> <input type="submit" name="submit" id="submit" value="Submit"/> </form> </div> <?php include('header.php'); ?> <?php include('footer.php'); ?> </body> </html>Send.php: <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $enquiry = $_POST['enquiry']; $security = $_POST['security']; $to = "example@Outlook.com"; $subject= "New Form Enquiry"; $message = "A potential employer has submitted an enquiry from your website:\n\n First Name: $firstname\n\n Last Name: $lastname\n\n Email: $email \n\n Enquiry: $enquiry\n\n You should probably respond."; if($security = "10"){ mail($to,$subject,$message); header("Location:php.php?s=1"); //php.php being the forms location }else{ header("Location:php.php?s=2"); //php.php being the forms location } ?>Any ideas would be much appreciated. Thanks. Edited by Coplestone, 17 January 2015 - 10:14 PM. It's about making a form for a web page. Which is better? Using table or divs? Which do you use? <form action='a.php' method='post'> <table> ............. </table> </form> <form action='a.php' method='post'> <div> ............. </div> </form> I'm very new to php, and so I haven't really mastered all the coding. But what I want to do is make a search form, which will search 15 different columns in a MySQL database. I've gone to a few different online walkthroughs, but I haven't managed to succeed as of yet. Can someone please show me the HTML and PHP coding required in order to make a search setup (the server is "localhost", the username is "root", the password is [blank], the database is "anzac war trophys" and the table is "anzac". And also assume that the collumns are called "a", "b", "c" and so on. Any help greatly appreciated! Hi, I'm trying to setup a quick PHP script that will grab the email from the url (see below) and after inserting into MySQL db - which is working fine - the script will complete two additional tasks: 1. send that same captured email out to a external db as in shown via http://domain1.com/insert.php?email=$lead (example), but then send to a DIFFERENT source - the originator of the lead - a portback acknowledgement using Header (sending the status and email to http://domain2.com/check.php?e=$lead&s=$status for their records). See the code below: ------------------------- Code: [Select] $lead = $_REQUEST['e_mail']; // will grab email from posted url string and assign to local variable $result = mysql_query($command); // this is just to execute the MySQL insert which works just fine but included here to explain validation below // Create API Call string to insert lead into iContact folder $requestURL = "http://domain1.com/insert.php?email=$lead"; // Execute API Call to CAKE $xml = simplexml_load_file($requestURL) or die("feed not loading"); if ($result) { $status = 1; // mark lead as sucess // send postback on lead status header("Location: http://domain2.com/check.php?e=$lead&s=$status"); } -------- Problem: I'm getting all sorts of errors with the simplexml_load_file() function and can't figure out why it won't work. Any input appreciated as this the only way I know how to pass the lead onward and then inform/update the other party of receipt of information. thanks! Windows 7, Apache 2.2.21 / PHP 5.3.5. What does the below error mean? I am new and fighting through this particular piece of code. Thank you in advance for your help. Warning: mysql() expects parameter 3 to be resource, string given in C:\website\do_createtable.php on line 3 <? $db_name="booster"; $connection=mysql("localhost", "USERNAME", "PASSWORD") or die (mysql_error()); $db=mysql_select_db($db_name, $connection) or die (mysql_error()); $sql="CREATE TABLE $_POST[table_name] ("; for ($i=0; $i < count($_POST[field_name]); $i++) { $sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i]; if ($_POST[field_length][$i] != "") { $sql .= " (".$_POST[field_length][$i]."),"; } else { $sql .= ","; } } $sql=substr($sql,0,-1); $sql .= ")"; $result=mysql_query($sql,$connection) or die (mysql_error()); if ($result) { $msg="<P>".$_POST[table_name]." has been created!</P>"; } ?> <HTML> <HEAD> <TITLE>Create a Database Table: Step 3</TITLE> </HEAD> <BODY> <h1>Adding table to <? echo "$db_name"; ?>....</h1> <? echo "$msg"; ?> </BODY> </HTML> I am using a simple email script called PHPmailer which works great but i would like to create a form so a user can input what the text for the email should be along with the subject from texts boxes, i also need the script to connect to a mysql database to get a list of email address to send to. Then once the user presses the send button the email is sent out to everyone in the database. Can anyone help me? <?php include_once('class.phpmailer.php'); $mail = new PHPMailer(); $body = eregi_replace("[\]",'',$body); $mail->IsSendmail(); // telling the class to use SendMail transport $mail->From = "zac@zpwebsites.com"; $mail->FromName = "First Last"; $mail->Subject = "PHPMailer Test Subject via smtp"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAddress("zacthespack@gmail.com", "John Doe"); $mail->AddAttachment("uploads/AleMail.pdf"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> I am need of some help on how to create a form with multiple receivers between tables. table1.field1 value is 10000 the form should allow a person to enter the id for those members to receive(separated by a comma) and the amount they each receive from table1.field1 then of course add the amount too each members account, and subtract the total from table1.field1 (and of course check if the value is high enough to distribute the desired amount between members. I need a little hand to get started here, so hopefully someone is willing to point me in the right direction Hi all New here. I have a basic email form that takes name phone email etc, also has 3 file upload boxes for photos. I have taken most of the code from free examples off the net and patched it together. It had an error message if something went wrong. I wanted to put an html page instead of just the txt. So read that I could end tag the php then do html then begin tag the php again. Problem is some of the error message was from a different part of the php code. How can i get this displayed on the html. Code: [Select] <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "email@email.com"; $email_subject = "JoinUs Model Form"; function died($error) { // your error code can go here ?> <title>title</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onload="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="sdadfsd" longdesc="http://www.dgfsfdg.com" /><br /> </p> <br /> <p>We are very sorry, but there were error(s) found with the form you submitted.</p> <p>These errors appear below.</p> ####### this is where i want the below errors to appear in same format as html ######### <p>Click back to fix your error(s) or you will be taken back to the form automatically in 10 seconds...</p> <h6> </h6> <h6>© asafdsodf 2012</h6> </body> </html> <?php die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['form2']['photo1']); $target_path = $target_path . basename( $_FILES['form2']['photo2']); $target_path = $target_path . basename( $_FILES['form2']['photo3']); $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $age = $_POST['age']; $city = $_POST['city']; $state = $_POST['state']; $height_feet = $_POST['height_feet']; $height_inches = $_POST['height_inches']; $photo1 = $_FILES['form2']['photo1']; $photo2 = $_FILES['form2']['photo2']; $photo3 = $_FILES['form2']['photo3']; $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Age: ".clean_string($age)."\n"; $email_message .= "Height: ".clean_string($height_feet) .clean_string($height_inches)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "State: ".clean_string($state)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; $email_message .= "".clean_string($comments)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <!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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>asdf </title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF"> <p><img src="./images/logo.png" width="326" height="144" alt="asdfahjdsfka" longdesc="http://www.kasdfhdskaha.com" /><br /> </p> <p>Thank your for applying to adskfha asdfasd. We will be in touch with you very soon.</p> <p>You will be redirected back to the site in 3 seconds...</p> <h6> </h6> <h6>© 2012</h6> </body> </html> <?php } ?> Thanks Wolfsta |