|
I can't seem to find any tutorials on this, so figured I'd ask here. Anyway I can filter a table of data by using a drop down in php?
|
# ? Mar 9, 2009 12:58 |
|
|
# ? May 15, 2024 22:06 |
|
Eararaldor, I put together a code example for you, and commented it for the most part. On your front end, (we'll call this index.html) Include jquery.js and jquery.form.js. Basically what the jquery.form.js will do is stop the submit event from going to the actual php script, and submit the post data through an AJAX call. This is where the magic happens. code:
Here is an example processForm.php file I wrote for you. code:
code:
http://www.littlesparrows.com/sa/dropfilter.rar has the code example, sql dump, and the sample style sheet(using 960.gs css framework) http://www.littlesparrows.com/sa/dropfilter is the demo url for you to see all of it in action. I make no guarantees that this is the best (or even secure) way of doing this. I simple just tossed it together for you really fast. Hope it helps. wil fucked around with this message at 21:27 on Mar 9, 2009 |
# ? Mar 9, 2009 17:30 |
|
Question: I am working on a site where I need a user to confirm their information... when they click the confirm button, I want it to send an e-mail to the site owner + post to authorize.net to begin the billing process. What is the best way for these two actions to be initiated from 1 button push? (since obviously the two actions are processed on different pages)
|
# ? Mar 9, 2009 22:50 |
|
KarmaticStylee posted:Question: You need to have a single script which handles the form (set the action= on the form with the button to this script). That script then validates the form input, and if its all ready to go, sends the mail. (mail() function, or however you want). Then it either uses header('Location: ...') to send the user to the authorize.net page, or uses cURL to make the http request. (depends what you're doing with it / whether the user needs to see it). If there's a problem with the data, the script uses header() to redirect back to the form page, possibly with some error info added to the URI. In short; php script != page user sees. KuruMonkey fucked around with this message at 23:01 on Mar 9, 2009 |
# ? Mar 9, 2009 22:59 |
|
KuruMonkey posted:You need to have a single script which handles the form (set the action= on the form with the button to this script). $host = "https://Simplecheckout.authorize.net"; $path = "/payment/CatalogPayment.aspx"; $data = "LinkId=1572e46b-fc81-5e7a-95b7-e3742cdegdbd"; $data = urlencode($data); header('POST '.$path); header('Host: '.$path); header('Content-type: x-ww-form-urlencoded'); header('Content-length: ' .strlen($data)); header($data); I get a 500 INTERNAL ERROR.. what am i doing wrong
|
# ? Mar 9, 2009 23:55 |
|
Ermmm, I think this is the problem... You're sending a POST back to the user's browser, which isn't valid. header() sets up http RESPONSE headers, POST is an http REQUEST header. requests go to servers, responses go to user agents (browsers). Your attempt to send a request to a user agent is resulting in a 500, because sending a request when a header is expected is...an internal server error You need to use header('Location: ...') that causes the browser to load the given URL I don't think you can send a POST to the browser hoping it will pipe it through to the given URL for you? I also don't think you can send POST variables through a header() call, you have to use GET. There may be a more involved solution to your particular requirements, if so I'm not sure what it is. (someone is going to tell me I'm wrong now...)
|
# ? Mar 10, 2009 00:10 |
|
Well I'm hoping I can just send extra data to authorize since they send order confirmation emails out when a transaction occurs anyway... still, wouldn't mind figuring out how to use headers to post
|
# ? Mar 10, 2009 00:12 |
|
Try turning your problem on its head... You could use javascript to trigger the email by using XMLHttpRequest in an onSubmit event; request a PHP script that does the email. (problem being that, as always, javascript can be disabled) Or... Rely on the info that comes back from authorize.net to notify the admin, not the form submission. (i.e. notification of success not attempt)
|
# ? Mar 10, 2009 00:29 |
|
What is the best way to detect if the end-user is using IE within PHP (not the html trick, but just PHP) I am doing this so far if (stristr((string)$_SERVER['HTTP_USER_AGENT'],'MSIE')) {...}
|
# ? Mar 10, 2009 04:09 |
|
I've copied and resized a picture before in PHP, but for some reason the image is resizing the correct size but comes out all black. php:<?php define('filename', "testResize/testSource.png"); define('sizeIncreasePercent', 5); // Get new sizes list($width, $height) = getimagesize(filename); define('newwidth', $width * sizeIncreasePercent); define('newheight', $height * sizeIncreasePercent); // Load define('thumb', imagecreatetruecolor(newwidth, newheight)); define('source', filename); // Resize imagecopyresized(thumb, source, 0, 0, 0, 0, newwidth, newheight, $width, $height); // Output imagepng(thumb, "testResize/test.png");; ?>
|
# ? Mar 10, 2009 06:59 |
|
What the gently caress? Why are you using define that way? Edit: also your problem is probably the fact that ImageCopyResized wants an image resource not a filename. Edit 2: drop the ImagePNG and you will probably see lots of warnings/errors.
|
# ? Mar 10, 2009 07:02 |
|
gibbed posted:What the gently caress? Why are you using define that way? I'm making constants for security reasons when I add onto the code. What exactly do you mean by image resource? Sorry for the dumb question, I just have no idea what you mean by this. I don't get any warnings or errors if I drop imagepng.
|
# ? Mar 10, 2009 07:17 |
|
awdio posted:I'm making constants for security reasons when I add onto the code. What exactly do you mean by image resource? Sorry for the dumb question, I just have no idea what you mean by this. ImageCopyResized Note the second argument. You're passing a string when it wants a resource, you'll want to use ImageCreateFromPNG() or equivilent to load the image you want to resize. You certainly should have gotten warnings or errors with your code, is your error reporting off? Where did you get the idea that constants somehow magically affect security?
|
# ? Mar 10, 2009 07:21 |
|
gibbed posted:ImageCopyResized Excellent! Changing it to this: define('source', imagecreatefrompng(filename)); worked! It's exactly the effect I need. No softness or blurring. I don't have error reporting off.. I don't know why it didn't give me errors. Everything is fine now though, thank you. The script may be used in a form, and I just think it's good practice for data that isn't going to change throughout the script to use a constant. I don't have exact plans how I'm going to change this code, but I know the constants can remain constants without a problem. I read about the importance of using constants in a form as a security measure here: http://dev.mysql.com/tech-resources/articles/php-security-ch02.pdf LP0 ON FIRE fucked around with this message at 07:43 on Mar 10, 2009 |
# ? Mar 10, 2009 07:37 |
|
I have no problem with newwidth/newheight being define()s (though I personally wouldn't do that). But the image resources (thumb, source) should definitly not be constants.
|
# ? Mar 10, 2009 09:19 |
|
Also, constants are almost always in all-caps.cannibustacap posted:What is the best way to detect if the end-user is using IE within PHP (not the html trick, but just PHP) Sounds about right. This is what Google tells me, and it looks like it's functionally identical: php:<? if (preg_match("/MSIE/i", $_SERVER["HTTP_USER_AGENT"])) { // stuff }?>
|
# ? Mar 10, 2009 13:22 |
|
wil posted:Eararaldor, I put together a code example for you, and commented it for the most part. Wow thats more than I actually hoped for. Thanks for your time this will help alot!
|
# ? Mar 10, 2009 13:59 |
|
cannibustacap posted:What is the best way to detect if the end-user is using IE within PHP (not the html trick, but just PHP) http://browsers.garykeith.com/downloads.asp The best way is to have someone else figure it out
|
# ? Mar 10, 2009 16:27 |
|
Munkeymon posted:http://browsers.garykeith.com/downloads.asp Thanks, I'll dig through that. At first, it seems a big non trivial though. By the way, what do you guys think of the $_SESSION variable? Does that work when a user has cookies disabled? Are there certain instances when you do not want to use $_SESSION? On PHP 5.2.3 (I believe)
|
# ? Mar 11, 2009 00:02 |
|
I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc.
|
# ? Mar 11, 2009 00:05 |
|
cannibustacap posted:By the way, what do you guys think of the $_SESSION variable? Does that work when a user has cookies disabled? Are there certain instances when you do not want to use $_SESSION? $_SESSION still uses cookies unless you explicitely have it put the SID in the url. What PHP does is kind of abstract away the need to manage the SID, Time to live and where to put the data (and more) and instead stores it all for you in static files. That static file is associated with the session ID which has been stored in the cookie or the url. They're nice if you don't know how cookies and session management work, but if you have the time to do it, you'd be better off learning how to do it by hand and managing it all in a database. You gain more control on what you do and can use the data outside of PHP if it's what you want (ie.: compile stats, distribute sessions over many servers, etc).
|
# ? Mar 11, 2009 00:10 |
|
TreFitty posted:I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc. From my personal experience, CakePHP is the easiest framework to learn and utilize. wil fucked around with this message at 23:43 on Mar 11, 2009 |
# ? Mar 11, 2009 00:26 |
|
TreFitty posted:I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc. In that regard, another good option that isn't in the OP is Agavi.
|
# ? Mar 11, 2009 00:29 |
|
TreFitty posted:I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc. CodeIgniter. But as gibbed said, your needs will dictate what you use, because they all have strengths and weaknesses. If you are just learning PHP, I'd suggest not using one for a while, until you notice you are writing the same bits of code (DB access, login handling, etc.) over and over. Then it's time to shop for a framework. Sure, you can walk into the dealership and buy a new car, but if you tinker with that old junker and get it running yourself, you'll know what's going on under the hood.
|
# ? Mar 11, 2009 06:27 |
|
I'm not going to say you're wrong, Lumpy. But the other way to look at is that a framework can act like the stabiliser wheels on a bike while you learn to ride. Also you can pick apart a framework to see how they've done the fiddly but important tasks like logins and db access... I would second CodeIgniter as a good framework for learning from, as it lets you use approximately none of its features if thats what you want (well, except the routing) Despite having personally jumped ship to Kohana, I'd advise against learners using it because apparently they think writing docs is a very low priority indeed, which CI are impressively more focussed on.
|
# ? Mar 11, 2009 13:27 |
|
KuruMonkey posted:I'm not going to say you're wrong, Lumpy. But the other way to look at is that a framework can act like the stabiliser wheels on a bike while you learn to ride. As I was typing up my reply, part of my brain was saying "yeah, but think of all the time you could have / would have saved had you started using one right away." I stuck with my guns though, because say you do use framework X to learn. Later on, you interview for a job that doesn't use one, or some hot chick wants you to fix her image gallery script for her pretty pony website, and will pay in sex but it doesn't use the framework you learned PHP on. You now have to spend the time learning stuff outside your comfort zone which can be harder once you've established a habit... "Wait, there's a *different* way to make DB connections other than $this->load->db() ???" If you learn with training wheels, and there is no incentive to ever take them off, if somebody presents you with a new bike that doesn't have them, you may be baffled. I do see your point, and I don't think learning *with* a framework is bad by any means, but having the motivation to go outside of it and look through it's source and so forth would be essential in my opinion.
|
# ? Mar 11, 2009 15:45 |
TreFitty posted:I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc. Don't use a framework, you don't need one with PHP.
|
|
# ? Mar 11, 2009 19:49 |
|
fletcher posted:Don't use a framework, you don't need one with PHP. I think this is the best way to get started. Except don't just copy and paste those files, use them as a basis for writing your own.
|
# ? Mar 11, 2009 23:00 |
|
And for the love of god use .php as the extension, not .inc, or at least .inc.php.
|
# ? Mar 12, 2009 05:41 |
|
gibbed posted:And for the love of god use .php as the extension, not .inc, or at least .inc.php. How will others learn from your mistakes if that can't view your raw, unparsed code via the web?
|
# ? Mar 12, 2009 14:18 |
|
Got another interesting question for you goons... In ASP.NET, theres a ASP.NET Calendar Control function. I was just wondering if theres something I can use that's similar in php? I'd rather not trust the user typing it out themselves, so an actual calendar popping up would be awesome.
|
# ? Mar 12, 2009 14:34 |
|
Eararaldor posted:Got another interesting question for you goons... The PHP language itself does not include any libraries of GUI elements. You'll need to find a 3rd party javascript thing to do this.
|
# ? Mar 12, 2009 14:36 |
|
JQuery has a UI package that has been pretty nice and I believe includes a calendar. I've been using the dialog, draggable and droppable bits and they've amazingly easy and reliable across browsers.
|
# ? Mar 12, 2009 14:58 |
|
Hi there I have only been dabbling in PHP for around a month and my only other experience in this sort of stuff is using ASP.NET. I am converting our companies static website into a more manageable (for me, as I will be the one updating it), streamlined PHP version. Everything is going fine apart from the question I am about to ask you. I have finished the staff profile pages which has cut out twenty odd static pages and would like to do the same with our news and events page. At present I have a number of Word documents that staff make and at present the only way to do this is to code each page. I have set up a news table in MySQL and and a foreign key linking it to the staff table which all works fine. The only trouble is I receive some Word documents with all sorts of formatting, bold text here, underlining here etc and was wondering whats the best way to insert that data? I have read up on htmlentities() and while that has worked great for things like pound signs and quotations there doesn't seem to be one for bold, italic, bullet points etc.. What is the best way to do this? I understand for some I could simply add the HTML tags in the textpad but I imagine this is a bit of a scummy way of doing things. Am I better creating some sort of input page for this data as the way I am inserting data into MySQL at present is a bit primitive. Any help appreciated.
|
# ? Mar 12, 2009 15:22 |
|
Eararaldor posted:Got another interesting question for you goons... Check out http://jqueryui.com/demos/datepicker/ If you like it I can write a quick little tutorial on how to implement it using PHP/Ajax.
|
# ? Mar 12, 2009 15:34 |
|
wil posted:Check out http://jqueryui.com/demos/datepicker/ Funny you should mention that. I was actually checking it out but was a little miffed as to how I actually implement it.
|
# ? Mar 12, 2009 16:39 |
|
Vedder posted:[...]The only trouble is I receive some Word documents with all sorts of formatting, bold text here, underlining here etc and was wondering whats the best way to insert that data? It was a neverending pain in the rear end for me in that situation. Generally I'd use Word's Export to HTML (different from "Save as HTML"), then HTML Tidy, then manually fix whatever goofiness remained, then grab the body of the page and throw it into the CMS. There's also "antiword" for Linux which extracts text from Word docs (I don't think anything post-Word 97), but it also strips formatting so you'd have to reapply it all over again. Making an input page is a good idea in theory, but if people are using Word to write for the web, it's guaranteed that they will just copy from Word and then paste into the form, which leads to all sorts of misery with the curly quotes and formatting. Things like FLK and TinyMCE just exacerbate the problem, because they look like Word so people expect them to actually be Word. I hate to say it, but if you have the power to make suggestions you might want to get contributors to use a WYSIWYG HTML editor rather than Word. You'll still have to clean it up, but at least it'll arrive with the entities already done and no wacky "mso:normal" sort of tags in it.
|
# ? Mar 12, 2009 17:31 |
|
How do I create a dynamically-generated file that prompts a user to download it? Say I have a form with 10 fields, once the user submits the form the file gets generated depending on the form's information and the user is prompted to download this file... only the file isn't actually on the server. Sort of like how gallery generators make the user's list but I don't think the file is ever actually saved to the server. Thanks!
|
# ? Mar 12, 2009 17:48 |
|
eHacked posted:How do I create a dynamically-generated file that prompts a user to download it? Set the header to attachment and just output what you want them to download.
|
# ? Mar 12, 2009 17:51 |
|
|
# ? May 15, 2024 22:06 |
|
duz posted:Set the header to attachment and just output what you want them to download. this: code:
That seems way too simple.
|
# ? Mar 12, 2009 17:56 |