Jump to content

next

Members
  • Posts

    140
  • Joined

  • Last visited

Everything posted by next

  1. I have a lot of forms that need to be processed. I used jQuery to collect all the data, but I don't know how to send it to PHP and get a response back. In .tpl my code is this: function submitSettings() { $('.forms').each(function() { $.post('<?php echo $action; ?>', $(this).serialize()); }); in controller on php side I have: if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) var_dump($this->request->post); It looks to me like data is being sent because as soon as I refresh the page I get logged out saying tocken is no longer valid, yet $this->request->post isn't being dumped Can anyone help?
  2. Thanks. Now if I could only figure out how to get this to work in OpenCart
  3. How do I submit forms in associative array format to PHP? Here's what I have so far: function submitSettings() { $('.forms').each(function() { $(this).serializeArray(); }); } looks like serialize creates assoc. array just like I need, but I don't understand how to pass the data to PHP. Can anyone help?
  4. How do I create a new array out of the following, and fill it only with few elements that I need: How do I extract just the following: [title] => first-banner [title] => next-banner [0] => speed [1] => speed number 2 [0] => random text [1] => some more random ttext Mary Christmas
  5. I'm using phpstorm. Right now, the only debugging I know is coding, then reading my errors in the browser window... I'm guessing it's a trashy way to work. I installed PHPstorm, I configured XDebug, I can run basic scripts and I'm able to read the output and debugging information in the IDE. However none of this works when I open an actual project. Project is utilizing MVC, so when I open a file that's buried somewhere inside one of the directories, my debugger is crying that it can't see certain classes and throws fatal errors. How do I configure my environment properly? I can't find what I need in PHPStorm help files
  6. Nice explanation, thank you
  7. I dropped PHP right as I started learning OOP, so my knowledge in it is very limited. However I'm trying to understand opencart, but it's a little confusing to me. Currently I'm looking at USPS functionality and can't figure out where all these methods and properties come from. Here's a snippet of USPS class: class ModelShippingUsps extends Model { public function getQuote($address) { $this->load->language('shipping/usps'); $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('usps_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')"); if (!$this->config->get('usps_geo_zone_id')) { $status = true; } elseif ($query->num_rows) { $status = true; } else { $status = false; } So, in the above, $this is basically ModelShippingUsps, if I remember correctly... ModelShippingUsps is an extension of Model and it inherits Model's methods and properties. This is what Model looks like: abstract class Model { protected $registry; public function __construct($registry) { $this->registry = $registry; } public function __get($key) { return $this->registry->get($key); } public function __set($key, $value) { $this->registry->set($key, $value); } } Where do config->get() and db->query come from? How does ModelShippingUsps has access to them? There's so much code and so little documentation on this cart, it's not even funny
  8. Found the problem. I was opening the html file locally (file///C:/blah blah blah), instead of through localhost. For whatever reason it's breaking ajax.
  9. Nah, it's the AJAX that doesn't work. I was originally getting some data because of the URL I used, it was incorrect. It's strange, responseText has no value in it, but when I look at the headers, something is being transmitted with the same number of characters as my PHP echo string. So if I change echo to 8 character word, I see that 8 characters are passed to my html page, but for whatever reason I can't see responseText.
  10. Why am I not able to edit my posts? Forget the above code, might seem like too much code. Here's a more basic example: js: function createRequestObject() { var tmpXmlHttpObject; //depending on what the browser supports, use the right way to create the XMLHttpRequest object if (window.XMLHttpRequest) tmpXmlHttpObject = new XMLHttpRequest(); // Mozilla, Safari would use this method ... else if (window.ActiveXObject) tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP"); // IE would use this method ... return tmpXmlHttpObject; } //call the above function to create the XMLHttpRequest object var http = createRequestObject(); function makeGetRequest() { //make a connection to the server ... specifying that you intend to make a GET request //to the server. Specifiy the page name and the URL parameters to send http.open('GET', 'http://localhost/test/test.php', true); //assign a handler for the response http.onreadystatechange = processResponse; //actually send the request to the server http.send(null); } function processResponse() { //check if the response has been received from the server if(http.readyState == 4){ //read and assign the response from the server var response = http.responseText; //do additional parsing of the response, if needed //in this case simply assign the response to the contents of the <div> on the page. document.getElementById('data').innerHTML = response; //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. //So it may be worth doing some basic error before setting the contents of the <div> } } PHP: <?php echo 'worked'; ?> HTML <html> <head></head> <script type="text/javascript" src="ajaxrequest.js"></script> <body> <a href="#" onclick="makeGetRequest()">Check status and DNE</a><br /> <!-- <a href="http://localhost/test/FmPilot%20validate.php" onclick="makeGetRequest()">Check status and DNE</a><br /> <a href="http://localhost/test/FmPilot billing.php">Create Invoices</a> --> <div id="data"> old text </div> </body> </html> It isn't working and I don't understand why.
  11. I can't seem to figure out how this works... This is my JS: function createRequestObject() { var tmpXmlHttpObject; //depending on what the browser supports, use the right way to create the XMLHttpRequest object if (window.XMLHttpRequest) tmpXmlHttpObject = new XMLHttpRequest(); // Mozilla, Safari would use this method ... else if (window.ActiveXObject) tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP"); // IE would use this method ... return tmpXmlHttpObject; } //call the above function to create the XMLHttpRequest object var http = createRequestObject(); function makeGetRequest() { //make a connection to the server ... specifying that you intend to make a GET request //to the server. Specifiy the page name and the URL parameters to send http.open('get', 'FmPilot validate.php'); //assign a handler for the response http.onreadystatechange = processResponse; //actually send the request to the server http.send(null); } function processResponse() { //check if the response has been received from the server if(http.readyState == 4){ //read and assign the response from the server var response = http.responseText; //do additional parsing of the response, if needed //in this case simply assign the response to the contents of the <div> on the page. document.getElementById('data').innerHTML = response; //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. //So it may be worth doing some basic error before setting the contents of the <div> } } My PHP code: <?php require('simple_html_dom.php'); require('functions.php'); $url = 'http://website'; $username = 'user'; $password = 'pass'; $ch = curl_init(); login($ch, $username, $password, $url); //read CSV file $geninv = getGenInvContent(); echo '<table border="1">'; echo '<th>Invoice </th>'; echo '<th>Work Order</th>'; echo '<th>PO</th>'; echo '<th>Status</th>'; echo '<th>DNE</th>'; echo '<th>Billing Total</th>'; echo '<th>Discrepancy</th>'; echo '<th>Paperwork</th>'; echo '<th>Web Invoice?</th>'; echo '<th>Billed on?</th>'; //loop through it line-by-line foreach($geninv as $invoice) { $dir = 'O:\Accounting Scanning\\'. $invoice['account'] . '\\' . date('Y') . '\\' . $invoice['bulk_invoice']; $result = findBackup($dir, $invoice['invoice']); // collect data off the web regarding current PO $data = getData($ch, $invoice['po_number']); $invoiced_with = isset($data['vendorInvNum']) ? $data['vendorInvNum'] : ''; echo '<tr>'; //if paperwork is found if ($result) { foreach($result as $key=>$signed_workorder) $invoice['backup'.$key] = $signed_workorder; } $difference = round($invoice['total'] - $data['dne'], 2); echo '<td>'.$invoice['invoice'].'</td>'; echo '<td>'.$invoice['workorder'].'</td>'; echo '<td>'.$invoice['po_number'].'</td>'; echo '<td>'.$data['wostatus'].'</td>'; echo '<td>'.$data['dne'].'</td>'; echo '<td>'.$invoice['total'].'</td>'; echo '<td>'. $difference .'</td>'; if ($result) { echo '<td>'; for ($i = 0; $i < count($result); $i++) echo $invoice['backup'.$i].'</br>'; echo '</td>'; unset($result); } else { echo '<td>PAPERWORK NOT FOUND</td>'; } echo '<td>'.$invoiced_with.'</td>'; if ($invoiced_with != '') echo '<td>'.$data['invoicedate'].'</td>'; else echo '<td></td>'; echo '</tr>'; if ($data['wostatus'] <> 'PVINV') { $not_billable[] = array ( 'invoice' => $invoice['invoice'], 'workorder' => $invoice['workorder'], 'po_number' => $invoice['po_number'], 'wostatus' => $data['wostatus'], 'dne' => $data['dne'], 'total' => $invoice['total'] ); } } echo '</table>'; if (isset($not_billable)) exportNB($not_billable); curl_close($ch); ?> My form: <html> <head></head> <script type="text/javascript" src="ajaxrequest.js"></script> <body> <a href="http://localhost/test/FmPilot validate.php" onclick="makeGetRequest()">Check status and DNE</a><br /> <a href="http://localhost/test/FmPilot billing.php">Create Invoices</a> <div id="data"> </div> </body> </html> What I'm trying to do is display all those PHP echoes without reloading, but it isn't working... Looks like AJAX is working, but all it displays is this: '; echo 'Invoice '; echo 'Work Order'; echo 'PO'; echo 'Status'; echo 'DNE'; echo 'Billing Total'; echo 'Discrepancy'; echo 'Paperwork'; echo 'Web Invoice?'; echo 'Billed on?'; //loop through it line-by-line foreach($geninv as $invoice) { $dir = 'O:\Accounting Scanning\\'. $invoice['account'] . '\\' . date('Y') . '\\' . $invoice['bulk_invoice']; $result = findBackup($dir, $invoice['invoice']); // collect data off the web regarding current PO $data = getData($ch, $invoice['po_number']); $invoiced_with = isset($data['vendorInvNum']) ? $data['vendorInvNum'] : ''; echo ''; //if paperwork is found if ($result) { foreach($result as $key=>$signed_workorder) $invoice['backup'.$key] = $signed_workorder; } $difference = round($invoice['total'] - $data['dne'], 2); echo ''.$invoice['invoice'].''; echo ''.$invoice['workorder'].''; echo ''.$invoice['po_number'].''; echo ''.$data['wostatus'].''; echo ''.$data['dne'].''; echo ''.$invoice['total'].''; echo ''. $difference .''; if ($result) { echo ''; for ($i = 0; $i < count($result); $i++) echo $invoice['backup'.$i].' '; echo ''; unset($result); } else { echo 'PAPERWORK NOT FOUND'; } echo ''.$invoiced_with.''; if ($invoiced_with != '') echo ''.$data['invoicedate'].''; else echo ''; echo ''; if ($data['wostatus'] <> 'PVINV') { $not_billable[] = array ( 'invoice' => $invoice['invoice'], 'workorder' => $invoice['workorder'], 'po_number' => $invoice['po_number'], 'wostatus' => $data['wostatus'], 'dne' => $data['dne'], 'total' => $invoice['total'] ); } } echo ''; if (isset($not_billable)) exportNB($not_billable); curl_close($ch); ?> it's a bit of my PHP code. Then, a few seconds later the page refreshes and I get my normal values from php. How do I get it to work the way I need?
  12. Sorry, I should stop doing this. I figured it out. I should have been populating my array like this: $data[$item->name] = $item->value;
  13. I populate $data array with this code: foreach($el as $item) $data[] = array($item->name => $item->value); var_dump shows the following inside $data: array(32) { [0]=> array(1) { ["submitted"]=> string(1) "Y" } [1]=> array(1) { ["type"]=> string(5) "labor" } [2]=> array(1) { ["wonum"]=> string(9) "XX-111111" } [3]=> array(1) { ... yet when I want to access wonum element I get an error: Undefined index: wonum in C:\xampp\htdocs\test\test.php on line 94 This is how I'm accessing it: echo $data['wonum']; Why is it not working?
  14. Just realized that these values are in hidden fields of a form. Oops! Thank you
  15. How do I retrieve values of post fields? For instance when I look at a page with Temper Data FF extension, it shows a bunch of post fields, some of them are blank, but some have values already preset. Example: subtotal = 70 priorApproval = False How can I get those values and put them into variables for future use? P.S. they aren't visible in URL itself.
  16. Yeah I tried that as well, wasn't really getting anywhere, but as soon as I changed the array name to "pics" it worked without an issue. Weird.
  17. nvm I figured it out. I guess images is a built in array and I can't be using that name, and my If statement had a faulty logic.
  18. Oh, ok. I wish I could use jQ, but for this code I'm not allowed to call other files (like libraries).
  19. I place several images into an array, then call the elements to change the picture, but instead changing source to a URL, my array stores: [object HTMLImageElement]? Why??? if (this.id == 'next') { if (images.length > i+1) { i++; } else { if (i != 0) i--; } document.getElementById('gallery').src = images[i]; that's the code. Also, why my conditionals aren't working as supposed to? For instance I thought that: if (images.length > i) would stop the image swap, but it doesn't, unless I change it to the awkward version above, In my current example array had 2 elements and "i" is set to 0. I click the link once "i" becomes 1, then I click it again, but the conditional doesn't stop it even though "i" becomes a 2 (and if I understand correctly 2 isn't greater than 2).
  20. JS: script type="text/javascript"> i=0; function fadeOut(ms) { var opacity = 1; function funcOut() { opacity -= 0.1; document.getElementById("gallery").style.opacity = opacity; if (opacity <= 0) { window.clearInterval(fadingOut); } } var fadingOut = window.setInterval(funcOut, ms); } function fadeIn(ms) { var opacity = 0; function funcIn() { opacity += 0.1; document.getElementById("gallery").style.opacity = opacity; if (opacity >= 1) { window.clearInterval(fadingIn); } } var fadingIn = window.setInterval(funcIn, ms); } function swap() { i++; if (i%2) { fadeOut(500); document.getElementById("gallery").src = 'http://www.collectiondx.com/files/BatmanARTFX5.JPG'; fadeIn(500); } else { fadeOut(500); document.getElementById("gallery").src = 'http://ecx.images-amazon.com/images/I/41Wm2rA8sbL._SL500_AA300_.jpg'; fadeIn(500); } } </script> html: <img class="fltrt" onload="setInterval(swap, 1500)" src="http://ecx.images-amazon.com/images/I/41Wm2rA8sbL._SL500_AA300_.jpg" width="400" height="400" alt="batman" id="gallery" /> there are 3 functions: fadeOut, fadeIn and swap. Swap is basically calling fadeOut, to animate fade out of the image, then it supposed to change the image and fade in. However it doesn't work as it should. I checked fadeOut, it works perfectly; then I checked fadeIn, it also works well; I verified value of "i" to make sure that i%0 alternates images as it should, and that works too! Lastly I checked the html is each each image swap, and that worked fine. What's going on? Every part of the code works as it should, yet when I put it all together it's broken. It fades and swaps, but not in set intervals and out of order. Can anyone suggest a solution?
  21. ok so changing the way I passed login data fixed my problem: $login_data = 'txtUserid=my_username&txtPassword=my_password'; I'm examining a function that I found online: function login($url,$data) { $fp = fopen("cookie.txt", "w"); fclose($fp); $login = curl_init(); curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($login, CURLOPT_TIMEOUT, 40000); curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($login, CURLOPT_URL, $url); curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($login, CURLOPT_POST, TRUE); curl_setopt($login, CURLOPT_POSTFIELDS, $data); ob_start(); return curl_exec ($login); ob_end_clean(); curl_close ($login); unset($login); } Is the function written wrong or does "return" not end functions, and they go until the closing brace? Like in this part ob_start(); return curl_exec ($login); ob_end_clean(); curl_close ($login); unset($login); wouldn't the function stop and return value at "return"?
  22. I don't have access to how that website works on the backend. I interact with it on regular basis and was hoping to automate a bunch of things. So what causes the data to post when using curl? CURLOPT_POST => true is this basically a submit button action?
  23. That page is accessible only by logged on users. I redirected curl to it after I passed login info.
  24. Credentials are definitely correct. I set the SSL option as you suggested, but that didn't help. I'm not really sure regarding what data it needs. Here's the form html code <input name="hReturnUrl" value="/Express/ServiceDesk.asp" type="hidden"> <input name="timezoneoffset" value="300" type="hidden"> <table border="0" cellpadding="0" cellspacing="0"> <tbody><tr> <td colspan="2" height="10"><img src="/Express/Desk/images/transpix.gif" height="10"></td></tr> <tr> <td colspan="2" class="errmsg">Please enter a user name and password.</td></tr> <tr> <td colspan="2" height="10"><img src="/Express/Desk/images/transpix.gif" height="10"></td></tr> <tr> <td class="formheader" align="left" nowrap="" width="100"><a class="FormHeader" href="" style="text-decoration:none" onmouseout="javascript:clearInfo();" onmouseover="javascript:writeInfo('Enter your<BR>user name.');">User Name:</a> </td> <td class="Content" align="left" width="100%"><input class="formfield" name="txtUserid" maxlength="50" value="" type="text"></td> </tr> <tr> <td class="formheader" align="left" width="100"><a class="FormHeader" href="" style="text-decoration:none" onmouseout="javascript:clearInfo();" onmouseover="javascript:writeInfo('Enter your<BR>password.');">Password:</a> </td> <td class="Content" align="left" width="100%"><input class="formfield" name="txtPassword" maxlength="50" type="password"></td> </tr> <tr> <td> </td> <td align="left"><br> <a href="javascript:document.frmServiceDesk.submit();"><img src="/Express/Desk/images/Max5Style/btn_login.gif" border="0"></a> <a href="javascript:document.frmServiceDesk.reset();"><img src="/Express/Desk/images/Max5Style/btn_clear.gif" border="0"></a> </td> </tr> <tr> <td colspan="2"><img src="/Express/Desk/images/transpix.gif" height="15"></td></tr> <tr> <td> </td> <td align="left"><a href="/Express/Desk/RetPass.asp"><img src="/Express/Desk/images/Max5Style/btn_retrievepassword.gif" border="0"></a></td> </tr> <tr> <td colspan="2" height="10"><img src="/Express/Desk/images/transpix.gif" height="10"></td></tr> <tr> <td colspan="2"><font class="ErrMsg">This web site is optimized for Internet Explorer 6.0 and above. Please note this web site may not operate correctly with other browsers.</font></td> </tr> <tr> <td colspan="2" height="10"><img src="/Express/Desk/images/transpix.gif" height="10"></td></tr> </tbody></table> This is what submits the form: javascript:document.frmServiceDesk.submit()
×
×
  • 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.