Jump to content

maxxd

Gurus
  • Posts

    1,651
  • Joined

  • Last visited

  • Days Won

    51

maxxd last won the day on January 7

maxxd had the most liked content!

About maxxd

Contact Methods

  • Website URL
    https://maxxwv.com

Profile Information

  • Gender
    Not Telling
  • Location
    North Carolina

Recent Profile Visitors

24,362 profile views

maxxd's Achievements

Prolific Member

Prolific Member (5/5)

159

Reputation

41

Community Answers

  1. This is where an MVC-style approach to the server-side code comes in handy. The display logic is in the view, and the controller decides what to return. If the request to the controller is AJAX-based (or POST, in this case) the controller returns JSON-encoded data whereas if it's not, it returns the full compiled HTML.
  2. Whatever you end up doing with the email itself, do yourself a favor and use one of the major libraries instead of php's native mail() function. I'm most familiar with PHPMailer, but I believe laravel uses Symfony Mailer. Either is going to make your like much easier in the long run.
  3. You require_once and use statements need to be outside the function; they're global functions. You can then use the classes inside a function. So, the instance that works, just put everything after require statements into a function and call it normally.
  4. Structure-wise, I agree with mac_gyver. This is really no different than the hotel booking system you were working on before. A single cinema booking can consist of multiple seats, much like a single hotel booking can consist of multiple rooms. Take a step back, think about what you know from past experience, and re-evaluate your current data design; in this case I very much doubt that a "booking" is a single seat.
  5. The ajax call doesn't interact directly with the php - the only time it'll register a failure is when the call itself fails. So if you call a non-existent endpoint or if the server is down, the ajax call will invoke the error method. If however the php can't find the record or there is an error in your code that doesn't halt the execution of said code, there will still be a successful response from the server and the ajax will treat it as a successful response. What typically happens is the php script returns a json-encoded array with a 'success' index that indicates whether or not the php function worked. This is what I meant when I said 'just have php return the status of the call' - add a boolean to the return payload that can tell the javascript if the php failed in a manner that didn't cause a server exception.
  6. Sorry, I was multitasking and therefor distracted earlier (hence my deleted post). I can give you a quick example using the fetch() api though it's been a while since I've used jquery ajax functions so I couldn't get that working - hopefully this'll still give you a nudge in the right direction. Unsolicited opinion; it's worth looking into fetch() or axios() if you want to move beyond jquery. I find them both simpler to use and easier to read (especially axios). Having said that, there's nothing wrong with jquery but it's not something I personally have seen used for new development in a while. html: <form action="" id="my-form"> <input type="text" name="test-1" id="test-1"> <input type="text" name="test-2" id="test-2"> <input type="submit" value="Click me"> </form> javascript: let frm = document.getElementById('my-form'); frm.onsubmit = e => { e.preventDefault(); let dt = new FormData(e.target); dt.append('new-value', 'test-3'); let ret = fetch('/jstest2-handle.php', { method: 'post', body: dt }).then(d => { return d.text(); }).then(ret => { console.log(ret); }); } jtest2-handle.php: print(json_encode([ 'var1' => 'return1', 'var2' => 'return2', 'varPost1' => $_POST['test-1'], 'varPost2' => $_POST['test-2'], 'varPost3' => $_POST['new-value'] ])); The console.log() output is this: {"var1":"return1","var2":"return2","varPost1":"test1","varPost2":"test2","varPost3":"test-3"} Obviously I put 'test1' into the `test-1` input, and 'test2' into the `test-2` input.
  7. Yes - ajax will load the specified php script and it will execute. In your sample code, you're not passing a variable named 'submit', so your php code won't run. It's been a bit since I've used jQuery, but it should be a simple case of collecting the data and sending it in the second parameter of the $.post() method from the javascript. The php will receive the data and any output will be returned to the calling script.
  8. If all the code is yours, just have php return the status of the call. If you're interfacing with a third party API, check your developer tool's network tab. You can see the request being sent and chances are the third party sends a response packet. Either way, best bet is to console.log the ajax response.
  9. In most CSS setups, there's a containing div set with 'overflow: hidden' and an animated height - this then reveals the contents of any nested elements. AFAIR jQuery affects the height of not only the containing div, but the nested elements. So it makes sense that there's a difference in appearance - I'm not aware of a CSS-only solution that will do the "un-squishing" you can (as I recall, will) see with jQuery. That having been said, whether you're concerned about injection vulnerabilities or server downtime using a CDN-based version of jQuery, you pretty much don't need to be. As long as you're using (for instance) jsDeliver, cdnjs, or code.jquery.com, you can be reasonably assured that it's safe and reliable. And of course if the idea still bothers you, just download the file and include it directly from your own server. Funny aside - I didn't realize jQuery was still under active development until last week when I saw the v4 beta announcement.
  10. In addition to that, you're using $curPageName all over that code, but I don't see where it's defined outside the if conditional. This means that if $_GET['id'] is not set, neither is $curPageName.
  11. If you're on WordPress I'm going to assume you're using WooCommerce for your transactions. It's been a long time since I've used WP or WC, but I'd be surprised if there wasn't an affiliate program extension. I'd look in the WooCommerce marketplace.
  12. $_SERVER['DOCUMENT_ROOT'].'/inc/header.php'; This will work from any sub-directory, as long as the `inc` directory is at the top level of the file hierarchy.
  13. It's been a long time since I've touched WP, but as I remember it right now you're using a global action - it fires on every page. You can either override the specific templates you're looking to add the form to, or check the template name and conditionally output the form.
  14. I'm on Windows 11 and use WSL2 with Ubuntu 20 LTS - works like a charm. Create your site files in the Ubuntu filesystem and it's hella fast, as well. You could also use Docker if WSL2 doesn't work for you.
×
×
  • 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.