Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 11-12-2008, 06:53 PM   #1
Senior Warrior Member
War Room Member
 
Lance K's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
Contact Info
Send a message via Skype™ to Lance K
Default 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.

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

Lance K is offline   Reply With Quote
Old 11-12-2008, 07:12 PM   #2
WP Queen
War Room Member
 
Leanne King's Avatar
 
Join Date: Aug 2007
Location: Sydney , Australia
Posts: 1,105
Thanks: 9
Thanked 198 Times in 132 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile  View Member's YouTube Profile
Contact Info
Send a message via Skype™ to Leanne King
Default 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

Leanne King is offline   Reply With Quote
Old 11-12-2008, 09:13 PM   #3
Puppet Master
 
Mike Bogowski's Avatar
 
Join Date: Nov 2007
Location: Sydney, Australia.
Posts: 628
Thanks: 7
Thanked 62 Times in 18 Posts
Default 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

Puppets are people too
Mike Bogowski is offline   Reply With Quote
Old 11-13-2008, 12:14 AM   #4
The Manic Marketer
War Room Member
 
Sean Donahoe's Avatar
 
Join Date: Jul 2008
Location: California, USA
Posts: 2,471
Blog Entries: 3
Thanks: 89
Thanked 463 Times in 219 Posts
Social Networking View Member's Twitter Profile 
Default Re: Can PHP do this?

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>
You can put the actual javascript in an external .js file so it does not appear directly on every page and that will do the job nicely for you.

Hope that helps!

To Your Wealth,

Sean Donahoe
The Manic Marketer

Sean Donahoe is offline   Reply With Quote
Old 11-13-2008, 08:25 AM   #5
Senior Warrior Member
War Room Member
 
Lance K's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
Contact Info
Send a message via Skype™ to Lance K
Default 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?

"You can have everything in life that you want if you
just give enough other people what they want."
~ Zig Ziglar

Lance K is offline   Reply With Quote
Old 11-13-2008, 08:39 AM   #6
The Manic Marketer
War Room Member
 
Sean Donahoe's Avatar
 
Join Date: Jul 2008
Location: California, USA
Posts: 2,471
Blog Entries: 3
Thanks: 89
Thanked 463 Times in 219 Posts
Social Networking View Member's Twitter Profile 
Default 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

Sean Donahoe is offline   Reply With Quote
Old 11-13-2008, 08:53 AM   #7
Senior Warrior Member
War Room Member
 
Lance K's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
Contact Info
Send a message via Skype™ to Lance K
Default Re: Can PHP do this?

Quote:
Originally Posted by Sean Donahoe View Post
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
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

Lance K is offline   Reply With Quote
Old 11-13-2008, 08:59 AM   #8
Senior Warrior Member
War Room Member
 
Neil Morgan's Avatar
 
Join Date: Jun 2007
Location: Lanarkshire UK
Posts: 2,487
Thanks: 98
Thanked 314 Times in 223 Posts
Social Networking View Member's Twitter Profile 
Default 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

Neil Morgan is offline   Reply With Quote
Old 11-13-2008, 09:06 AM   #9
Web Developer
 
wayfarer's Avatar
 
Join Date: Nov 2008
Location: Asheville, NC USA
Posts: 420
Thanks: 18
Thanked 57 Times in 51 Posts
Social Networking View Member's Twitter Profile 
Default 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.

Wayfarer | join me on StoryBlorg
wayfarer is offline   Reply With Quote
Old 11-13-2008, 11:49 AM   #10
Entrepenerd.com
War Room Member
 
entrepenerd's Avatar
 
Join Date: Apr 2008
Location: Logansport, IN, USA.
Posts: 670
Thanks: 129
Thanked 78 Times in 33 Posts
Social Networking View Member's Twitter Profile  View Member's YouTube Profile
Contact Info
Send a message via AIM to entrepenerd Send a message via Yahoo to entrepenerd Send a message via Skype™ to entrepenerd
Default 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">
<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>
Then in the processor all you would need is something like:

<?php
header("Location: $_POST['section']");
?>

Signature currently down for maintenance... sorry for any inconvenience
entrepenerd is offline   Reply With Quote
Old 11-13-2008, 12:08 PM   #11
Senior Warrior Member
War Room Member
 
DonTino's Avatar
 
Join Date: Jan 2003
Location: Cologne, Germany
Posts: 1,605
Blog Entries: 2
Thanks: 46
Thanked 67 Times in 8 Posts
Social Networking View Member's Twitter Profile 
Default 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

DonTino is offline   Reply With Quote
Old 11-13-2008, 03:51 PM   #12
HyperActive Warrior
War Room Member
 
rwil02's Avatar
 
Join Date: May 2005
Location: Auckland, New Zealand.
Posts: 241
Thanks: 0
Thanked 13 Times in 12 Posts
Social Networking View Member's Twitter Profile 
Default Re: Can PHP do this?

Quote:
Originally Posted by entrepenerd View Post
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>

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:
head er("Loc ation: ".repl ace(_POST['section']," ""_").".html"); 
or similar
WARNING: Not a PHP programmer, just a programmer. and mind the random spaces added to not break the forum

rwil02 is offline   Reply With Quote
Old 11-13-2008, 04:41 PM   #13
Senior Warrior Member
War Room Member
 
Lance K's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
Contact Info
Send a message via Skype™ to Lance K
Default Re: Can PHP do this?

Quote:
Originally Posted by rwil02 View Post
I'd avoid doing that as you probably want to use the state for something else (like saving to a database).
Actually, the only thing I want to use the field value for is to determine which page to send the person to after hitting submit. I don't need to save anything. I just need to get certain people to certain pages based on information (partial or whole) that they input into a field.

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

Lance K is offline   Reply With Quote
Old 11-13-2008, 05:37 PM   #14
HyperActive Warrior
War Room Member
 
rwil02's Avatar
 
Join Date: May 2005
Location: Auckland, New Zealand.
Posts: 241
Thanks: 0
Thanked 13 Times in 12 Posts
Social Networking View Member's Twitter Profile 
Default Re: Can PHP do this?

Quote:
Originally Posted by Lance K View Post
Actually, the only thing I want to use the field value for is to determine which page to send the person to after hitting submit. I don't need to save anything. I just need to get certain people to certain pages based on information (partial or whole) that they input into a field.

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!

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)

rwil02 is offline   Reply With Quote
Old 11-13-2008, 05:49 PM   #15
Senior Warrior Member
War Room Member
 
Lance K's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 3,866
Thanks: 1,435
Thanked 646 Times in 405 Posts
Contact Info
Send a message via Skype™ to Lance K
Default 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.

"You can have everything in life that you want if you
just give enough other people what they want."
~ Zig Ziglar

Lance K is offline   Reply With Quote
Old 11-13-2008, 08:22 PM   #16
Warrior Member
 
Join Date: Oct 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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...
}
}
xanol is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
php

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 03:09 PM.