PHP - Convert Form Values To Object?
How does everyone take data input from an HTML Form and convert it into an Object in OOP?
I am thinking it would be better if user inputs resided in an object so that I could manipulate the data in OOP terms instead of referencing the Form procedurally. TomTees Similar TutorialsWell the topic may not sound very explicit. So I'll do my best to explain it here. I have a pull down menu as part of a form, which contains the months of the year. I'm trying to store the value of this form entry using the $_POST['month'] variable into a database but first, I need to convert the month values into their corresponding integer values( that is 1 for January, 2 for February etc), in order to easily do date calculations later down the road. Any ideas about how to do this? It may be helpful to include the code for the pull down menu. Code: [Select] <p><tab> Date of Birth: <?php //Make the month pull down menu. //Array to store months. $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); print '<select name= "month">'; foreach ($months as $key => $value) { print "\n<option value=\"$key\">$value</option>"; } print '</select>'; ?> </tab> <tab> <?php //Make the day pull down menu print '<select name= "day">'; for ($day = 1; $day <= 31; $day++) { print "\n<option value=\"$day\">$day</option>"; } print '</select>'; ?> </tab> <tab><?php //Make the year pull down menu print '<select name= "year">'; $start_year = date('Y'); for ($y = ($start_year - 18); $y >= 1900; $y--) { print "\n<option value=\"$y\">$y</option>"; } print '</select>'; ?> </tab> </p> Hey, If i have a string which contains numbers and symbols... such as 1:2:4 (its not always : for the symbol it changes) Is there a function that can convert the numbers that are 9 or less to have a 0 infront of them such as: 01:02:04 (also this is not timestamp format - just normal strings) I have a file that is uploaded by the user that has a series of rows of data in an html table. The columns are always a constant, but the number of rows in the file can change. These rows of the html table are the only information in the file when I am processing it. I need to either convert the file to a CSV file or write the values to a CSV list so that I can then insert them into a database. Any suggestions would be wonderful...I've spent the last three hours spinning my wheels. Here is an example of one row of data from the file: Code: [Select] <tr><td bgcolor=#dddddd class=dataFT >5 (Excellent)</td><td bgcolor=#dddddd class=dataFT >5 (Excellent)</td><td bgcolor=#dddddd class=dataFT >5 (Excellent)</td><td bgcolor=#dddddd class=dataFT > </td><td bgcolor=#dddddd class=dataFT > </td><td bgcolor=#dddddd class=dataFT >DATA</td><td bgcolor=#dddddd class=dataFT >1015020</td><td bgcolor=#dddddd class=dataFT >155498322</td><td bgcolor=#dddddd class=dataFT >DATA</td><td bgcolor=#dddddd class=dataFT >4731751</td><td bgcolor=#dddddd class=dataFT >2011-09-25 11:18:33 (-5:00)</td><td bgcolor=#dddddd class=dataFT >2011-09-25 12:16:50 (-5:00)</td><td bgcolor=#dddddd class=dataFT >0:58:17</td><td bgcolor=#dddddd class=dataFT >0:58:16</td><td bgcolor=#dddddd class=dataFT >DATA</td><td bgcolor=#dddddd class=dataFT >DATA</td><td bgcolor=#dddddd class=dataFT >DATA</td><td bgcolor=#dddddd class=dataFT >Resolved</td></tr> I want to save class property values and want to write these in the database after being called from another function. Code: [Select] class model{ public $dbh; public $user_arr=array('username','password','email','location','interest','homepage'); public function insert_data() { $sql = "INSERT INTO account VALUES ('" .$user_info['username']."','".$user_info['password'] ."','".$user_info['email']."', 'user','".$user_info['location']."','".$user_info['interests'] ."','".$user_info['homepage']."')"; //if(isset($data)) echo $sql; } public function data_approoved($user){ //$user_info = new array(); $user_arr['username'] = $user['username']; $user_arr['password'] = $user['password']; $user_arr['email'] = $user['email']; $user_arr['location'] = $user['location']; $user_info['interests'] = $user['interests']; $user_info['homepage'] = $user['homepage']; Model::insert_data(); } } }//class ended The approoved_data function is supposed to set the values of $user_info array which should be later on stored in database. Please somebody help me. I call a web service and it retuens the values in the following format
$response = $client->submitRequest($requestParams);Which returns stdClass Object ( [return] => stdClass Object ( [result_code] => 0 [result_data] => City[0]=Chicago [message_text] => ) )what I want is just the value for [result_data] => City[0]=Chicagoassigned to a variable Psedo Code $city = [result_data] => City[0]=Chicago;so that $city = Chicago; I want to create an application for sending mails using PHPMailer by placing it on my website server (using SMTP), but I can not get object of class phpmailer to change its properties of: to_name to_email ContentType from default (i.e. null). Why are the properties keeping default values from the PHPMailer class, and not accepting my once, though I check values i get from DB and they are good. ContentType is set in a config file. Here is part of var_dump ($mailer); object of my extended class: object(MyMailer)#2 (56) { ["priority"]=> int(3) ["to_name"]=> NULL ["to_email"]=> NULL ... ["ContentType"]=> string(10) "text/plain"... also I get value of ["Port"]=> int(26) but ["SMTP_PORT"]=> int(25). I need to use smtp port 26. And here is the extended class of phpmailer require_once './PHPMailer/class.phpmailer.php'; require_once 'mailer-config.php'; class MyMailer extends PHPMailer { var $priority = 3; var $to_name = null; var $to_email = null; var $From = null; var $FromName = null; var $Sender = null; var $ContentType = null; function MyMailer() { global $eSlanje; // Comes from mailer-config.php $eSlanje array if($eSlanje['smtp_mode'] == 'enabled') { $this->Host = $eSlanje['smtp_host']; $this->Port = $eSlanje['smtp_port']; if($eSlanje['smtp_username'] != '') { $this->SMTPAuth = true; $this->Username = $eSlanje['smtp_username']; $this->Password = $eSlanje['smtp_password']; } $this->Mailer = "smtp"; } if(!$this->From) { $this->From = $eSlanje['from_email']; } if(!$this->FromName) { $this->FromName = $eSlanje['from_name']; } if(!$this->Sender) { $this->Sender = $eSlanje['from_email']; } $this->Priority = $this->priority; //echo "<br>eSlanje[content_type]"; //var_dump ($eSlanje['content_type']); $this->ContentType = $eSlanje['content_type']; } } and here is the cofig file: mailer-config.php <?php $eSlanje['from_email'] = "hi@mysite.com"; $eSlanje['from_name'] = "Joe Blog"; $eSlanje['title'] = "hi there"; $eSlanje['content_type'] ="text/html"; $eSlanje['smtp_username'] = null; $eSlanje['smtp_mode'] = "enabled"; $eSlanje['smtp_port'] = 26; $eSlanje['smtp_host'] = "mail.mysite.com"; Here is where I insert values of email and name into the object: <?php session_start(); include ("password.php"); require_once 'class_lib/MyMailer.php'; require "class_lib/MySQL_Database.php"; require "get_email_template.php"; $db = new MySQL_Database (); $id = isset($_GET['id']) ? $_GET['id'] : false; $sql = "select email,ime from ".TABLE." where id = $id"; $query = mysql_query ($sql); $toClient = mysql_fetch_array($query); $to = isset($toClient['email']) ? $toClient['email'] : false; var_dump($to); // here I get a valid email address $to_name = isset($toClient['ime']) ? $toClient['ime'] : false; //var_dump($to_name); // here I get a valid preson's name $mailer = new MyMailer(); $mailer->AddAddress($to, $to_name); $mailer->Body = get_htmlBody(); $mailer->AltBody = get_txtBody(); if(!$mailer->Send()) { echo "<br> Mailer Error: " . $mailer->ErrorInfo." "; } else { echo "<br>message not sent  "; } $mailer->ClearAddresses(); var_dump($mailer); // this is where the object trace comes from ?> I have this form:
<form method="get"> I have a simple form and need to convert it to XML so I can send it to my payment gateway. I have the XML data types (?) they are expecting, but do not have a clue of how to build the string. Can someone help me out? Thanks, Debbie Hi guys! I need some help with a code problem. I've a form with 2 inputs, one single and one multiline, and I need to pass the value of both into an array, var1 (single input) is the same for every line and var2 (multiline) change with every line Hoe can i do it? Hey, been trying to make a form to upload an image to the server and also email the image as attachment. After nearly a week I managed to make it work. Only some validation needs to be done. My next step is to make it work for multiple files, ie. 5. The form will have 5 boxes to upload images and no more. I have tried a few different things with for loops ( ie for $i=0; $i<5; $i++ {...} ) but no luck. I can't think of any solution of a loop to upload multiple files and then email multiple attachment as my code. The code is: <?php session_start(); $imagename1 = $_FILES["uploadFile1"]["name"]; $_SESSION['imagename1'] = $imagename1; $imagename1 = $_SESSION['imagename1']; $imagetype1 = $_SESSION['imagetype1']; $imagesize1 = $_SESSION['imagesize1']; $imagetemp1 = $_SESSION['imagetemp1']; $thankyouurl = 'thankyou.php' ; $errorurl = 'error.php' ; $http_referrer = getenv( "HTTP_REFERER" ); $http_agent = getenv( "HTTP_USER_AGENT" ); $domain = $_SERVER['REMOTE_ADDR']; $filename = $_SESSION['uploadFilename']; if(isset($_POST['send'])) { $fp = fopen($imagetemp1, "rb"); $file = fread($fp, $imagesize1); $file = chunk_split(base64_encode($file)); $num = md5(time()); fclose($fp); // UPLOAD FILE // possible PHP upload errors $errors = array(1 => 'php.ini max file size exceeded', 2 => 'html form max file size exceeded', 3 => 'file upload was only partial', 4 => 'no file was attached'); // check the upload form was actually submitted else print form isset($_POST['send']) or error('the upload form is neaded', $uploadForm); // check for standard uploading errors ($_FILES[$fieldname1]['error'] == 0) or error($errors[$_FILES[$fieldname1]['error']], $uploadForm); // check that the file we are working on really was an HTTP upload @is_uploaded_file($_FILES[$fieldname1]['tmp_name']) or error('not an HTTP upload', $uploadForm); // validation... since this is an image upload script we // should run a check to make sure the upload is an image @getimagesize($_FILES[$fieldname1]['tmp_name']) or error('only image uploads are allowed', $uploadForm); // make a unique filename for the uploaded file and check it is // not taken... if it is keep trying until we find a vacant one $now = date("y-m-d_H-i-s", time()); while(file_exists($uploadFilename = $uploadsDirectory.$now.'_'.$_FILES[$fieldname1]['name'])) { $now++; } // now let's move the file to its final and allocate it with the new filename @move_uploaded_file($_FILES[$fieldname1]['tmp_name'] , $uploadFilename) or error('receiving directory insuffiecient permission', $uploadForm); $from= 'youremail@server.co.uk'; $emailTo = 'mail@hotmail.com'; $subject = 'Quote Form'; $body = "equipment_type: $equipment_type \n\nModel: $Model \n\nMake: $Make \n\nModelNumber: $ModelNumber"; $fp = $_SESSION['fp']; $file = $_SESSION['file']; $num = "==Multipart_Boundary_x{$semi_rand}x".$_SESSION['num']; $headers = 'From: Name <'.$from.'>' . "\r\n" . 'Reply-To: ' . $emailTo; //Normal headers $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/mixed; "; $headers .= "boundary=".$num."\r\n"; $headers .= "--$num\r\n"; // This two steps to help avoid spam $headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n"; $headers .= "X-Mailer: PHP v".phpversion()."\r\n"; // With message $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 8bit\r\n"; $headers .= "".$body."\n"; $headers .= "--".$num."\n"; // Attachment headers $headers .= "Content-Type:".$imagetype1." "; $headers .= "name=\"".$imagename1."\"r\n"; $headers .= "Content-Transfer-Encoding: base64\r\n"; $headers .= "Content-Disposition: attachment; "; $headers .= "filename=\"".$imagename1."\"\r\n\n"; $headers .= "".$file."\r\n"; $headers .= "--".$num."--"; mail($emailTo, $subject, $body, $headers); header( "Location: $thankyouurl" ); } ?> the form is like this Code: [Select] <input name="uploadFile1" id="uploadFile1" value="" class="file" type="file"/>can anyone suggest anything please? how can I form the for statement? much appreciated Hi. I have an input field where a date is entered, format dd-mm-yy. I need to query the database to see if this date exists. How can I convert the date to yyyymmdd before the query? Thanks Sorry if I asked this before in some variant, but I had to put my OOP studies aside for a few weeks, so here I go again?! I am trying to learn OOP and would like to take the data submitted in a form and put it into an object so I can pass that to other objects and do stuff with said data in OOP terms. My *limited* understanding of things so far is this... If I have form "registration.php", when the user clicks 'Submit' then data from the form gets populated immediately in the $_POST array and control would go to the action page... I would like to take - password - name into a generic object called FormHandler. (Maybe this isn't how the OOP gurus would do it, but hmor me as I am trying to learn elementary OOP, and use something that works for me.) So how would I go about doing that? All I can think is to have an action page called "form_handler.php" and when the user submits the form in "registration.php" then "form_handler.php" would instantiate FormHandler which would assign the $_POST array into either its own array or into individual variables. Maybe something like... class FormHandler{ private $someArray(); // OR private $email; private $password; private $name; function __construct() { $this->someArray = $_POST(); // OR $this->email = $_POST['email']; $this->password = $_POST['password']; $this->name = $_POST['name']; } } Feel free to tell me what you think of my code and idea, and please be nice because I have never written any OOP before and it is hard to break my old procedural ways! TomTees I have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. Hi, how would i display the date that is already in db and was submitted by user when he logs in to their profile? That code below works for the values like 'approved' 'denied' so on, but how would i do same for a date? thank you. Code: [Select] <?php include('config.php'); $uname=$_SESSION['username']; if($_SESSION['username']){ $sql="SELECT ApplicationStatus FROM table1 WHERE uname='$uname'"; $result=mysql_query($sql); $row = mysql_fetch_array($result);} echo '<form name="test" method="post"> <select name="ApplicationStatus"> <option value="">------</option> <option value="In process" '.(($row['column1']=='In process')?'selected="selected"':'').'>In process</option> <option value="Withdrawn" '.(($row['column1']=='Withdrawn')?'selected="selected"':'').'>Withdrawn</option> </select>'; ?> hi i was wondering how i can display the values for a form that already in db. users submitted a form and then when they log in to their profile they can change the value in a form, but the original value would show the one that they first submitted. makes sense? at the moment its set as blank, how would i display the option value to the one in the db on their profile? thanks Code: [Select] <form name="test" method="post"> <select name="ApplicationStatus"> <option value="'">------</option> <option value="In process">In process</option> <option value="Withdrawn">Withdrawn</option> </select> I have a form for a sign in page that I want the label for the form field to actually be displayed in the text box and clear when the box is selected to enter text. I've accomplished this using the code below and it works fine. The problem that I'm having is in IE the password field does not change to display dots or asterisk in place of each character. It works fine in Fire Fox but not in IE. Is there way to accomplish this using php or so that it is compatible with most browsers? Here's the code that I'm using: Code: [Select] <?php echo "<input type=\"text\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000'; this.type='password';}\"> "; ?> On one of my calculators : https://bizztools.net/2017/qccu/bizztools2015_budgetTest.php
When you press on the envelope in the middle you can send a form to yourself. I've added the code in the file that gets used to send the form to the person's email.
for ($i = 0; $i <= 79; $i++) { $item_Annual[$i] = number_format($_REQUEST['itemAnnualDisplay[$i]']); } Body: (each line of the form has a different value for $item_Annual) from 1 to 79 <TD bgcolor="#EEEEEE" align="left" valign="middle" height="1"><Font style="font-family:Arial; font-size: 12px;"><font color="#000000"> '.$currencySymbol.$item_Annual[1].' </TD>
for ($i = 0; $i <= 6; $i++) { $incomeSubtotal += $values[$i] * $periods[$i]; $itemAnnual[$i] = $values[$i] * $periods[$i]; $return['itemAnnualDisplay[$i]'] = $itemAnnual[$i]; } //New addtions are lines 3 and 4, the others were already there
Now, I've done some process of elimination and when testing to see if $periods[$i] and values[$i] would show up on the form, the values were zero for each. So each $itemAnnual[$i]is calculated to be $0. You can see from the form screenshot, the subtotals are calculating, but the individual items are not. Could this have anything to do with the form on the calculator page? It's in bootstrap.
Help please!!
Hello Everyone.. Im a programer in php with little experience. I have a form with 3 pages. 1st page display categories which come from category table. then user can select 1 or upto 3 category there. Then 2nd page display that selected categories and need to display relevant subject to that categories. In second page I use radio button for selected categories to keep a one category as a main category. each categories' subjects display with check boxes. In there too, user can select 1 or 3 more subject in to a particular category. In third form page, that my problem was encounter, there I need to print out selected category and their subjects in a table. first two pages are no problem for me and third form I have a problem in how to get categories and their subjects and they print as apiece in the page. like this category1 | subject1, subject2, subject3 category2 | subject1, subject2, subject3, subject and so forth. This same to my first form page Code: [Select] $q = 'SELECT * FROM category ORDER BY category_id'; $r = mysqli_query( $dbc, $q); $c = 0; $i = 0; echo '<form action="subjects.php" method="post">'; echo '<table class="form_table" ><tr>'; while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="category[]" value="' . $row['category_id'] . '" /> ' . $row['category_name'] . '</td>'; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; ?> In second page 'subjects.php' I use Code: [Select] if ( isset($_POST['submitted1']) && isset($_POST['category']) && sizeof( $_POST['category']) == 3 ) { $_SESSION['category'] = $_POST['category']; print_r ( $_SESSION['category']); $q = 'SELECT * FROM category ORDER BY category_id'; $r = mysqli_query( $dbc, $q); while($_SESSION = mysqli_fetch_array( $r, MYSQLI_ASSOC )){ foreach( $_POST['category'] as $value ) { if ( $value == $_SESSION['category_id']) { $q = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = {$_SESSION['category_id']}"; $r1 = mysqli_query( $dbc, $q); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($_SESSION = mysqli_fetch_array( $r1, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="subject[]" value="' . $_SESSION['subject_id'] . '" /> ' . $_SESSION['subjects'] . '</td>'; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } } } } Those two pages working properly. In third page that my problem page I tried something like this , but its not working. value come from subject.php page. Code: [Select] if ( ( isset($_POST['submitted2'])) && ( isset($_SESSION['category'])) && (isset( $_SESSION['subjects'])) && sizeof( $_SESSION['category']) == 1) { //$_SESSION['category'] = $_POST['category']; print_r ( $_SESSION['category']); echo 'good'; } elseif ( ( isset($_POST['submitted2'])) && ( isset($_SESSION['category'])) && (isset( $_POST['main_category'] ))) { print_r ( $_SESSION ); echo 'very good'; } So can any body tell me where is my mistake and help me fix this problem. any help greatly appreciated. thank you. I've got a form that submits values to itself and the user input values are saved into the database in a table with an auto incrementing ID. After SUBMIT is clicked, it reloads the page and all the values are gone, I'm wondering how I can get it to keep the values so that the user can make a single change and resubmit again. I know I can save all the values into the session or in the URL or pass them through $_POST in an array but I'm wondering what is the proper way to do this. Thanks. |