Jump to content

next

Members
  • Posts

    140
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

next's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  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.
×
×
  • 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.