![]() |
Can PHP do this? Can PHP take information from a form field and send users to a specific page upon hitting the submit button depending on the value in the field? For example, if I had a "State" field, could it take people from California to a specific page and people from New York to yet a different page? From what little I know about PHP I would guess that an else if type deal is what I'm looking for. If so, how would that code be put into the form so that it knows to look for the field input? Does this make sense? I'm not sure I'm explaining it the clearest. :o Thanks in advance for any help. Edit: Is it possible to only take part of the input from the field? So if someone put Arkansas and I only wanted to take "kansas" could it take people from Arkansas to the Kansas page? In other words, is it possible to evaluate only part of the input from a given field? |
Re: Can PHP do this? I looked at doing something similar a while back and my coder was going to use a sql database and php combined. Hope that helps. Leanne |
Re: Can PHP do this? Yup! This is actually quite easy to do and shouldn't take anyone who knows what theyre doing more than an hour or so. Hope this helps |
Re: Can PHP do this? You can actually do this easily with JavaScript. Code: <form>Hope that helps! To Your Wealth, Sean Donahoe The Manic Marketer |
Re: Can PHP do this? Thanks, Sean. I know virtually nothing about javascript. Isn't there a possibility that some users don't have it enabled? |
Re: Can PHP do this? It's unlikely that people have javascript disabled. Though some security software may block certain JS functions. Most of the time security tools block Java Applets (not JavaScript) so you should be fine. To Your Wealth, Sean Donahoe The Manic Marketer |
Re: Can PHP do this? Quote:
|
Re: Can PHP do this? In the form: <form method="POST" action="process.php"> <p><select name="section"> <option selected>Select State</option> <option>- - - - - - - - - - - - - - - - -</option> <option>California</option> <option>Texas</option> <option>New York</option> </select></p> </form> In process.php, something like: <?php switch($_POST['section']) { case('California'): header("Location:http://www.mydomain.com/california.html"); break; case('Texas'): header("Location:http://www.mydomain.com/texas.html"); break; } ?> This is very rough but you get the idea. Cheers, Neil |
Re: Can PHP do this? My recommendation is not to use JavaScript, but to use the idea above, with $_POST data and header(). JavaScript is much too slow, and the header() function takes advantage of the natural HTTP header protocol, which means the browser treats the redirect as if it is being sent directly to the new page, meaning the back button will not break. |
Re: Can PHP do this? I'd try to avoid all the "case" statements if possible. You could easily pass the value of the page to jump as the value of the option selected like below for example: Code: <form method="POST" action="process.php"><?php header("Location: $_POST['section']"); ?> |
Re: Can PHP do this? entrepenerd gave the best and most likely most simple way to do this with PHP. I'd also avoid Javascript if you don't know what your doing. PHP would be the best solution for something like this. In the sample entrepened provided you can also use full urls like http://www.website.com/ instead of only site.html Tino |
Re: Can PHP do this? Quote:
I'd avoid doing that as you probably want to use the state for something else (like saving to a database). I'd use the switch with a to lower case conversion to avoid potential issues. if ALL cases have a page to handle them, you could replace the switch with a PHP Code: WARNING: Not a PHP programmer, just a programmer. and mind the random spaces added to not break the forum |
Re: Can PHP do this? Quote:
For example, if I had a "favorite food" field and wanted a form submitted with the word "cream" in it to go to a page for a local creamery, would it be possible to redirect people who answer "ice cream" to the "cream" page? I just want to be able to send a person to a specific page upon submit based on all or part of what they input in a specific form field. Hope that clears it up a little. Thanks for all the ideas so far! :) |
Re: Can PHP do this? Quote:
Ok. That's a bit more complicated than just matching one thing to one other thing. To do things like that you are looking at (at minimum) a string map a -> b, goto b in descending order of length (most specific match) eg ice cream -> cream cream -> cream ice -> ice cubes which means you need to set up and maintain a mapping file of some sort. beyond that you start getting into search engine type territory. stemming (cream = creams, creamed, creamy, etc) and lexographical mapping (toilet = loo, cr_pper, dunny, lavatory) if you just want a simple mapping, driven by a combo box, then that info can be stored in the drop down list. you can use cream as the value for both ice cream and cream display text, and that will work as long as you don't present that data back to the user again (because then it would pick the first option in the list as a match) |
Re: Can PHP do this? Actually, I'd only be interested in finding the word "cream". So whether they type "whipped cream" "ice cream" "sour cream" wouldn't matter. Anything with the word "cream" as part of the answer goes to the "cream" page. The rest of the input would be irrelevant. I just want to be able to flag certain words. Another example would be if I wanted the word "ant". If someone typed in "irrelevant" it would go to the "ant" page. Kind of like the broad search function works here. Is there a way to search a field for certain text? Sooner or later I'll be able to articulate exactly what I'm looking to do. Thanks for being patient. |
Re: Can PHP do this? Use strpos() So... $mappings = ('cream' => 'cream url', 'ant' => 'ant url'); $inputFromUser = strtolower($_POST['somefield']); foreach ($mappings as $search => $url) { if (strpos($inputFromUser,$search)) { //send to $url, or do whatever... } } |
| All times are GMT -6. The time now is 09:57 AM. |