![]() | | ||||||||
| | #1 |
| Senior Warrior Member War Room Member Join Date: Jun 2006 Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
|
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. ![]() 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? |
| "You can have everything in life that you want if you just give enough other people what they want." ~ Zig Ziglar | |
| | |
| | #2 |
| WP Queen War Room Member Join Date: Aug 2007 Location: Sydney , Australia
Posts: 1,105
Thanks: 9
Thanked 198 Times in 132 Posts
|
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 |
| | |
| | |
| | #3 |
| Puppet Master Join Date: Nov 2007 Location: Sydney, Australia.
Posts: 628
Thanks: 7
Thanked 62 Times in 18 Posts
|
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 |
|
Puppets are people too
| |
| | |
| | #4 |
| The Manic Marketer War Room Member Join Date: Jul 2008 Location: California, USA
Posts: 2,471
Blog Entries: 3 Thanks: 89
Thanked 463 Times in 219 Posts
|
You can actually do this easily with JavaScript. Code: <form>
<p><select name="section" size="1" language="javascript" onChange="pagejump(this.selectedIndex);">
<option selected>Select State</option>
<option>- - - - - - - - - - - - - - - - -</option>
<option>California</option>
<option>Texas</option>
<option>New York</option>
</select></p>
</form>
</center>
<script language="JavaScript">
<!--
function pagejump(varItem)
{
switch(varItem)
{
case 0:
window.parent.self.status="";
break;
case 1:
window.parent.self.status="";
break;
case 2:
window.location="http://www.yourdomain.com/california";
break;
case 3:
window.location="http://www.yourdomain.com/texas";
break;
case 4:
window.location="http://www.yourdomain.com/texas";
break;
}
}
// -->
</script> Hope that helps! To Your Wealth, Sean Donahoe The Manic Marketer |
| | |
| | |
| | #5 |
| Senior Warrior Member War Room Member Join Date: Jun 2006 Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
|
Thanks, Sean. I know virtually nothing about javascript. Isn't there a possibility that some users don't have it enabled?
|
| "You can have everything in life that you want if you just give enough other people what they want." ~ Zig Ziglar | |
| | |
| | #6 |
| The Manic Marketer War Room Member Join Date: Jul 2008 Location: California, USA
Posts: 2,471
Blog Entries: 3 Thanks: 89
Thanked 463 Times in 219 Posts
|
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 |
| | |
| | |
| | #7 |
| Senior Warrior Member War Room Member Join Date: Jun 2006 Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
| Thanks again, Sean. To be clear, you think it would be easier to go the JS route than PHP or PHP & MySQL? Which would be less expensive to have developed? And should cost of development be a deciding factor or are there enough other reasons to use one route over another? And finally, do you do any custom freelance programming?
|
| "You can have everything in life that you want if you just give enough other people what they want." ~ Zig Ziglar | |
| | |
| | #8 |
| Senior Warrior Member War Room Member Join Date: Jun 2007 Location: Lanarkshire UK
Posts: 2,487
Thanks: 98
Thanked 314 Times in 223 Posts
|
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 |
| | |
| | |
| | #9 |
| Web Developer Join Date: Nov 2008 Location: Asheville, NC USA
Posts: 420
Thanks: 18
Thanked 57 Times in 51 Posts
|
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.
|
| Wayfarer | join me on StoryBlorg | |
| | |
| | #10 |
| Entrepenerd.com War Room Member Join Date: Apr 2008 Location: Logansport, IN, USA.
Posts: 670
Thanks: 129
Thanked 78 Times in 33 Posts
|
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"> <p><select name="section"> <option selected>Select State</option> <option>- - - - - - - - - - - - - - - - -</option> <option value="california.html">California</option> <option value="texas.html">Texas</option> <option value="new_york.html">New York</option> </select></p> </form> <?php header("Location: $_POST['section']"); ?> |
|
Signature currently down for maintenance... sorry for any inconvenience
| |
| | |
| | #11 |
| Senior Warrior Member War Room Member Join Date: Jan 2003 Location: Cologne, Germany
Posts: 1,605
Blog Entries: 2 Thanks: 46
Thanked 67 Times in 8 Posts
|
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 |
| | |
| | |
| | #12 | |
| HyperActive Warrior War Room Member Join Date: May 2005 Location: Auckland, New Zealand.
Posts: 241
Thanks: 0
Thanked 13 Times in 12 Posts
| 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 | |
| | ||
| | |
| | #13 | |
| Senior Warrior Member War Room Member Join Date: Jun 2006 Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
| 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! | |
| "You can have everything in life that you want if you just give enough other people what they want." ~ Zig Ziglar | ||
| | |
| | #14 | |
| HyperActive Warrior War Room Member Join Date: May 2005 Location: Auckland, New Zealand.
Posts: 241
Thanks: 0
Thanked 13 Times in 12 Posts
| 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) | |
| | ||
| | |
| | #15 |
| Senior Warrior Member War Room Member Join Date: Jun 2006 Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
|
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. |
| "You can have everything in life that you want if you just give enough other people what they want." ~ Zig Ziglar | |
| | |
| | #16 |
| Warrior Member Join Date: Oct 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
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... } } |
| | |
![]() |
|
| Tags |
| php |
| Thread Tools | |
| |
![]() |