Jump to content

n1concepts

Members
  • Posts

    195
  • Joined

  • Last visited

Everything posted by n1concepts

  1. I found the answer and I (again) made it more complicated than it should have been... Link: http://webcheatsheet.com/php/multidimensional_arrays.php
  2. I need a way to where I capture form content - product information via $_POST and insert that info into sessions so I can later display that info back via the 1st array's key. Example: If the following products and that product's info is as follow: Product1 - feature xxx - 9.99 Product2 - feature yyy - 13.41 Product3 - feature zzz - 13.84 Q: how can I setup a multi-array to where I assign the attributes inside the 1st array then loop through the first array, which would be $_SESSION['product'][0], $_SESSION['product'][1], etc... then parse and display each assigned value (feature & price) for that specified product? I'm not clearly on defining the multi-demensional array and then looping through the 1st array - getting to the 2nd to display the attributes before incrementing to the next key in the array 1st. Can someone provided an example? I need this to manage the order of information inserted in a form to print labels for shipments.
  3. I figured I was which reason I asked... I see exactly what you are saying that that's exactly what I needed - Thx!
  4. Also, one user (session) may loop through the search form three to four hundred times - selecting 300 to 400 unique product id's to which I'll then need to query to pull each product's info to print each accordingly. This is why i need to figure out a way to save each form search / query (per user) to complete the final query. Note: the reason i have to do it this way is b/c they will be entering sku #'s in a text field so it will repeat each time they need to perform a new search. Got it?
  5. So is it possible I can use that 'unique' session id - per user/location - and on the SQL INSERT, include that variable to save the data to a record (updating it accordingly until no more additions)? Then query the database - based on the session id to pull that record back up - with all the saved fields, to query each of those individual records to print? I'll probably need to save that session_id as a different variable so I can delete that entire database record once the print task is complete - to save disk space. Note: I understand the theory about a session; need a possible solution / design but thanks for response.
  6. Hi, I got a scenario to where I've hard coded the login (user name & password) that will be used by multiple locations to access a database to query and print out inventory lables (that part coded and all queries working without issue). Problem: I need a method to where I can store (each individual entity's) select data - i.e. productss 1,2,3,4,5, etc... for that particular session - and once all selected records confirmed <by that specified user>, loop through that saved data to print out that data accordingly. My issue (that's giving me trouble coming up w/design): 1. I have to use the 'hard-coded' global login which will be assigned to all locations <creating unique logins not possible> 2. There are 400 to 500 products and the objectives is to allow each user - remember, they all will have the exact same username & password which reason I can't distinguish between them - to search and select the ones they need printed out - labels. Therefore, I need to save each search (results) temporarily until that user advise, "NO additioinal searches required" adding to array or table - at that point, it should loop back through the saved data and print out to a page. Note: Being there will only be one GENERAL login that will be used by all, I currently don't see how I can manage this with MySQL - being MySQL really not required to save the data b/c soon as they print the selected info, it's no longer required. For this reason, I was thinking about temporary tables are PHP Sessions but not sure if either suitable for this setup. If I could save each user's session as that - a session - sending each (form submission) to s session's array to later loop through it to query final set of data to print out it out then kill that session, that would be perfect. Problem is I haven't been able to figure out the logic /code. EXAMPLE: $product_id = 1; // this would be the results 1st search that I need saved (temporarily until the final loop on that saved array queried for print function) $product_id = 4; // this would be results of 2nd search $product_id = 8 // this would be results of 3rd search, etc... until they click "NO" to stop returning to search form. At that point, that's when I need to query the $product[] array or session - looping through it to retrive all the saved product_ids as shown above... I thought doing something like: $products[] = $_REQUEST['product_id']; // for the 1st loop $_SESSION['products'] = $products; // then create a session to save that info before returning to the search form for another query // then for later subbsions, there would be IF/Else check to know the session exist so simply add new element to end of existing array array_push($_SESSION['products'], $products_id); Can anyone advise and possibly provide and example or either? For the temp tables, I'm not sure this would work b/c if multiple locations (users) start building a search at same time, they may cancel one another out. Sort of stumped on this one but I know there is a way to save the data (hopefully in a session) to later loop through that session to print info out? Note: I only need to save the record id as they search through database and once they click (no more searches), that's when I then need to loop through the saed array to SELECT each record's specific info to print each out accordingly.
  7. Hi, I'm working on a form to where I need to be able to (dynamically) add additional input text box (as shown in the code below) as they are required: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title></title> <link href="styles/list_style.css" rel="stylesheet" type="text/css" media="screen"> <!-- Start AJAX --> <script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","includes/getproducts.php?q="+str,true); xmlhttp.send(); } </script> <!-- End AJAX --> </head> <body> Body Content - Header <div id="container"> Create 3 x7 Divs Here <div>Each Div is </div> <div> <form> Product 1: <input type="text" name"product" onKeyUp="showUser(this.value)"> </form> <br /> <div id="txtHint"><b>Product info will be listed here.</b></div> </div> <!-- End "container" DIV --> </div> </body> </html> As with this example which currently show one text field Q1: How can I add a button or link where when clicked, it will add an additional input text box? Q2: In doing so, should I create a loop to add a number value to each 'name' - i.e. product1, product2, product3, etc... or can I just call the results back in the $product[] array? Any examples and or suggestions appreciated as I'm lost on this one. thanks!
  8. Actually, that was my next thought - I'm just going to setup a centralized MySQL db and use the token to validat the sessions. Yeah, that's the best and certainly a secure method. Thx!
  9. I think I may have a way - using Sessions. Here's my thinking: PHP makes a name/value pair available in a constant named SID if a cookie value for a session ID cannot be found. To that, I think I may be able to do something like this: <a href="www.abc.com?<?php echo SID; ?>">Testing</a> which should reach the browser as: <a href="www.abc.com?html?PHPSESSIS=xxxxxxxxxxxxxwhich will be the encrypted session xxxxxx">Testing</a> Note: I just have to ensure session_start() defined on the receiving page and this would then be recognized. Of course, I'll set this as a automatic (timer) redirect but explaining in this format for discussion. I will try this and advise - thx!
  10. Yeah, that's the issue - passing data cross (external) domains. I know it can be done with $_SESSIONS but that's overboard for what I want to accomplish - it's not sensitive information so no problem using $_GET (appending to string to pass along). My only requirement is that I want to acknowledge - from the receiving domains - that the redirect came from that one specific source (www.portal.com) and no other referral or the data capture won't be logged. Reason: this way, I can keep "direct" views from being logged as a hit <they have to originate or coming from www.portal.com>. It looks like "HTTP_REFERER" the option - I will just match on that link.
  11. Hi, I want to control a variable (decide whether to track click if coming from a specific site oppose to hitting the final site (destination) directly. For example: www.portal.com - this will be a management site that will redirect viewers to the the final destination based on variable info - for exmample $a=123 or $a= 567 - which would come in as www.portal.com?a=123 or www.portal.com?a=567 Note: 123 would redirect to www.abc.com?a=123 and/or 567 would redirect to www.xyz.com?a=567 with said variable(s). ------ My question is this: What is the best method to authenticate (both on) www.abc.com and/or www.xyz.com that the referred viewer came from www.portal.com? I know about the super globals (HTTP_REFERER) but want to know if there are other (more) secure method to manage this interaction between external domains /websites? Any insight on this appreciated - thx!
  12. Hi, Can someone point me to either a tutorial or code that displays random number - to simulate changing entries such as 'open' positions left to be filled for an event? For example, say the value is set at 400, i need to then decrement that count down to 1 but during the 'countdown' process, randomly change between 400 and 1 to simulate open or filled positions. Example: count switches from 398 to 381, from 381 to 261, from 261 to 138, from 138 to 318, etc.... Is this possible w/JS? If so, can you point me to example code to review. Thx!
  13. Hi, I just want to get afew opinions on the best way to define this code which will (literately) be the same on multiple pages. Note: objective is to check for an existing set of $_SESSION variables and redirect accordingly (will be placed at top of each page). My question is, "can't this be define as a function - passing in the required values?" and if so, "are there any issues managing secured logins in this manner? Here's the snippet of code for review - not as a function: if (($_SESSION['uname']) && ($_SESSION['access'] == 2)) { #if already logged in, redirect based on dept id if ($_SESSION['dept'] == 1) { header("Location: admin/index.php"); } elseif ($_SESSION['dept'] != 1) { header("Location: cases/cases-list.php"); } else { // If access is not GRANTED then reset and hold user at login page unset($_SESSION['uname']); unset($_SESSION['access']); header("Location: index.php"); } } So, my question is "what is the correct method of defining this as a function - passing in three variables which would all be sessions 'uname', 'access', 'dept'? thx!
  14. Hi, I'm working with a PHP script but have a pop - using JS - to open a new form to which I need to insert a variable to that URL but not sure how to accomplish. Here's the current code which works but without the append variable: <?php $_REQUEST[cid] = 123; echo "<strong><A href=# onclick=\"window.open(http://domain.com/email.php?caseid=$_REQUEST[cid]);\">Send a Email</A></strong>"; ?> What I need is for the popup page - which is http://domain.com/email.php to include that variable 'caseid' which should be 123. I can't define the correct logic to produce the correct results - including the variable. Any help w/this appreciated - thx!
  15. Thanks for both your answers - The logic works exact! (appreciate, litebearer). And, "yes, I actually created an array for all and looped thru - defining each line of code with the various elements (in this case the USA states). Thanks again - I just had a brain freeze on coding it for he dd menu.
  16. Need some help to define the php logic to echo back a selection if/when chosen from the drop down menu. Note: I'm using just a small subset of the USA states to show setup and what I'm trying to accomplish - it will be the same for all the other drop down menus as well.... Here's the example code: <form name="form1" method="post" action="<?php $_SERVER[php_SELF]; ?>"> <select name="address_state" id="address_state" tabindex="25"> <option value="" selected> - Select State -</option> <option value="AK">Alaska</option> <option value="AL">Alabama</option> <option value="AR">Arkansas</option> <option value="AZ">Arizona</option> <option value="CA">California</option> <option value="CO">Colorado</option> <option value="CT">Connecticut</option> <option value="DC">District of Columbia</option> </select> <input name="submit" type="submit" value="submit" tabindex="900" id="submit" /> </form> Issue: I have validation (logic) define to check all the (other) text, radio, and check boxes of the form and that all works great! However, any time one of those particular fields fail validation, any selected "drop down" item is lost - it defaults back to no selection and the user has to make all drop down menu selections again. Can someone provide method to echo back - in php being the page reloads to itself - the drop down selection as in the example above? Thanks!
  17. 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: ------------------------- $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. thx!
  18. Hi, Anyone got a php script that provides the ability for an email form to give the sender the ability to attach MULTIPLE file attachments to the outgoing message? I know how to build the stand email form in PHP but having issues defining the 'file attachment' portion - and with the ability to allow multiple file insertions to append to the email. Any references (links) to script examples that accomplish this objective appreciated. Thx!
  19. Wow! I see that it did work for you... Now, I'm really tripping.... thx! One last question: you you know of any method where you can post data to a 3rd party form and control the redirect after that data submission? Other than what I've defined using cURL? I need to make an API call to submit the data in some method but then keep the user from being redirected on their page b/c it's just raw unstructured xml code; when users see that data it appears as if there is an error. therefore, i want to redirect them to our own confirmation page. You can see what I did from the code I provided but it (for some reason) not working w/vendor - but it works fine on my test site.
  20. Copy and load the entire script and you'll see the form which contains the four fields (3 text and the 1 textarea field which is name 'notes'). The form is basic and although there is cURL code that's not impacting what should be happening - I just defined a basic 'foreach' loop and parsing through the array - adding the four fields to $post_data[] to prepare to be sent w/cURL. Again, the problem is when you submit the form, the string that is produced show $_post['notes'] alters in name and the '&' sign which is required to append the field to string also changed so I know something is seeing those characters incorrectly and changing them. Reason: if you change $post_data['notes'] to something other than 'note' and resubmit, it works just fine. For example: change $post_data['notes'] to $post_data['comments'] and notice the difference in string - the '&' sign then appears and 'comments' is correctly displayed in the string. That's what I can't figure out: I have to get 'notes' to display correctly as that's what's expected on the receiving side which I have no control to change...
  21. Hi, Can someone explain to me the reason why $_POST['notes'] keeps getting altered to '¬es=null' as in the example below from the PHP cURL code? Results: contact_title=mr&first_name=john&last_name=doe¬es=null&submit=submit Notes that $_POST['notes'] is displayed in the string as '¬es' and the '&' sign is even missing when appending to string. Now, the strange thing about it is if you change the name for that field to something other than 'notes' it works without an issue as shown below: contact_title=mr&first_name=john&last_name=doe&comments=null&submit=submit Notice: I changed the field name to 'comments' and that field name appended properly to the string as '&comments' My issue is I have to use the field name 'notes' for the textarea box b/c the 3rd party source that needs to receive the data requires that name. Plus, I have to use cURL to post the data so I can force the redirect to our confirmation page instead of theirs - therefore, standar post method won't work. I think I have the cURL part to grab and sumbit the form data correct and will test that soon as I can get past the 'notes' field issue - just need to update the URL for redirect but I can't figure out why the 'notes' textarea name getting distorted on post - I'm stuck! Here's the code which when loaded in php file, should echo the $_POST string when submit button clicked in form: <?php //create array of data to be posted if (isset($_POST['submit'])) { // setting default values if empty if ($_POST['notes'] =='') { $_POST['notes'] = 'null'; } // THE ONE IN QUESTION IS: $post_data['notes']= $_POST['notes']; $post_data['contact_title']= $_POST['contact_title']; $post_data['first_name']= $_POST['first_name']; $post_data['last_name']= $_POST['last_name']; $post_data['notes']= $_POST['notes']; $post_data['submit']= $_POST['submit']; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); echo $post_string."<br /><br /><hr />"; // $post_string .= "&notes=".$_POST['notes']; //echo $post_string; exit(); // I'm stopping the code here until I can figure out why $post_data['notes'] not displaying correctly //create cURL connection // $curl_connection = curl_init('http://xxx.domain.com'); //set options curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 0); //set data to be posted curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); //perform our request $result = curl_exec($curl_connection); //show information regarding the request //print_r(curl_getinfo($curl_connection)); //echo curl_errno($curl_connection) . '-' . curl_error($curl_connection); //close the connection curl_close($curl_connection); unset($_POST['submit']); // reset field for new post entry to avoid reprocessing old data // Redirect to confirmation page header("Location: index.php"); // redirect to Home page once values submitted to remote site for processing } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title></title> </head> <body bgcolor="#F2F2E6" topmargin="0"> <div align="center"> <table border="0" cellpadding="0" cellspacing="0" width="801" align="center"> <tr></tr> <tr> <td valign="top" bgcolor="#FFFFFF" colspan="10"> <p align="right"></td> <td height=""></td> </tr> <tr> <td valign="top" bgcolor="#FFFFFF" rowspan="2" colspan="2"> </td> <td valign="top" bgcolor="#FFFFFF" colspan="6" height="2"></td> <td valign="top" bgcolor="#FFFFFF" rowspan="2" colspan="3"> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan="2" valign="top" align="left"> </td> <td colspan="3" align="left" valign="top" bgcolor="#FFFFFF"><form name="form1" method="post" action="<?php $_SERVER[php_SELF]; ?>"> <div class="htitle">Contact Information</div> <div class="hleftspacer15"> <table width="550" border="0"> <tr> <td width="135" class="smalltext1">Job Title</td> <td width="405"><input name="contact_title" type="text" id="contact_title" tabindex="70"></td> </tr> <tr> <td class="smalltext1">First Name <span class="redAsterisk">*</span></td> <td><input name="first_name" type="text" id="first_name" tabindex="75"> </td> </tr> <tr> <td>Last Name <span class="redAsterisk">*</span></td> <td><input name="last_name" type="text" id="last_name" tabindex="80"> </td> </tr> <tr> <td width="135" align="left" valign="middle" class="smalltext1">Comments</td> <td width="405"> <textarea name="notes" id="notes" cols="35" rows="4" tabindex="65"></textarea> </td> </tr> </table> </div> <div class="sbtn"> <input name="submit" type="submit" value="submit" tabindex="900" id="submit" /> </form></td> <td valign="top" bgcolor="#FFFFFF" height="119"> </td> </tr> <tr> <td></td> <td bgcolor="#FFFFFF" height="33" colspan="10"><p align="center"></td> </tr> </table> </div> </body> </html>
  22. Hi, I have some javascript defined that is working correctly to check if one of the two radio buttons checked prior to allowing submit to complete. However, I have a 2nd button which performs a 'redirect' which I can't figure out how to include on that JS validation process to echo 'error3' if neither radio button not checked prior to the defined redirect for that button. Can someone advise how I can include the 'ddsumbit' button to to that JS validation script to ensure one of the radio buttons are checked before redirecting to link? The code is below - thx! <script type="text/javascript"> // script.js handle the form submit event on form (below) entitled form.html function prepareEventHandlers() { document.getElementById("form3").onsubmit = function() { if ((document.getElementById("func_0").checked == true) || (document.getElementById("func_1").checked == true)) { document.getElementById("error3").innerHTML = ""; // to STOP the form from submitting return true; // uncomment this line to have submit working //return false; // remove line when using in the real world } else { // reset and allow the form to submit document.getElementById("error3").innerHTML = "A SELECTION IS REQUIRED"; return false; } }; } // when the document loads window.onload = function() { prepareEventHandlers(); }; </script> Here's the radio buttons & the two buttons code that is defined within the form: <form action="index.php" method="post" name="form3" id="form3"> <span id="error3"></span> <input type="radio" name="func" value="work" id="func_0" /> <input type="radio" name="func" value="nonwork" id="func_1" /> <input type="submit" name="submit3" id="submit3" value="next>" tabindex="15" /> <input type="button" name="ddsubmit" id="ddsumbit" onClick="location.href='cancel.php'" value="decline" tabindex="20" /> </form>
  23. I found this JavaScript code that works flawlessly in ensuring an email (or at least something for that field) is defined. However, I need to modify this code to ensure a "radio" button is selected and if not, similar error message is shown on the form web page & preventing the form from being submitted. Here's the original code - which is unedited (I need it updated to validate the 'radio' button group' in the form: // script.js handle the form submit event on form (below) entitled form.html function prepareEventHandlers() { document.getElementById("form3").onsubmit = function() { // I NEED THE BELOW LOGIC CHANGED TO VALIDATE RADIO BUTTON IS CHECKED. if (document.getElementById("func").value == "") { document.getElementById("errorMessage").innerHTML = "Please select option via radio button!"; // to STOP the form from submitting return false; } else { // reset and allow the form to submit document.getElementById("errorMessage").innerHTML = ""; return true; } }; } // when the document loads window.onload = function() { prepareEventHandlers(); }; AND here is the actual form (form.html) I want the error message to appear if no radio button selected: <form action="includes/validate.php" method="post" name="form3" id="form3"> <input type="radio" name="func" value="work" id="func_0" /> <input type="radio" name="func" value="nonwork" id="func_1" /> <span id="errorMessage"></span> <input type="submit" name="submit3" id="submit3" class="rcorners" value="next>" tabindex="15" /></td> </form> <script src="script.js"></script> Note: the 'errorMessage' id is where Error message should put - which is the case if I was validating on email field. Again, I need some help to modify the (above) JS script to check if one of the "func" radio buttons selected before allowing form to be submitted. If neither button selected, then error message appear within SPAN tag id 'errorMessage'. Thx for help!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.