|
|
|
|
![]() ![]() |
Sep 11 2006, 03:56 AM
Post
#1
|
|
|
Advanced Member Group: Members Posts: 190 Joined: 16-February 06 From: Egypt Member No.: 11,326 |
I just made this form in order to redirect me to the page selected by a user, but it doesn't do that, it just reload the entire page:
CODE <form name="broker" action="?" method="get"> <select name"select"> <option value="" selected>Select one below...</option> <option value="http://www.msn.com">MSN</option> <option value="http://www.yahoo.com">Yahoo</option> </select> <input type ="submit" name="submit" value="Choose"> </form> i hope any body can help in this. This post has been edited by XIII: Sep 11 2006, 05:39 AM |
|
|
|
Sep 11 2006, 07:52 AM
Post
#2
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 1,002 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
First of all, you are missing an '=' sign after "select name" in the second line.
I'm no expert when it comes to forms, but shouldn't you fill in the "action" part? After clicking submit, the form should "give" the information to a PHP file, which then deals with the choice, and redirect to the wanted web site. Here's how I would make it. page.html HTML <form name="broker" action="form.php" method="post"> <select name="select"> <option value="0" selected>Select one below...</option> <option value="1">MSN</option> <option value="2">Yahoo</option> </select> <input type ="submit" name="submit" value="Choose"> </form> As you can see, I changed the action and the method, as well as option values. form.php CODE <?php $choice = $_POST['select']; if ($choice == 0) { echo "You haven't chosen anything.<br /><a href=\"java script: history.go(-1)\">Go back</a>"; } else { if ($choice == 1 { header( 'Location: http://www.msn.com/' ); } else { header( 'Location: http://www.yahoo.com/' ); } } ?> Here we have an IF statement, which deals with the selected option. If the user didn't select anything, he would get a message and a link back to the form. If he/she did select option 1 or 2, the PHP file would redirect the browser to MSN/Yahoo. This might not work, since I googled for most of the code, and assembled it with no PHP knowledge |
|
|
|
Sep 11 2006, 04:12 PM
Post
#3
|
|
|
Advanced Member Group: Members Posts: 127 Joined: 31-August 06 Member No.: 15,636 |
Don't worry Pal, you're not the only one, I say from personal experince, honestly.
I ahve tried a gazillion times to get my forms to work but they never have, so I've just had to live with it. usually its the lacking of something like "Sendto=e-mail<>" or something like that with the word redirect, but I have to date, still had nil improvement in making a succesful form. The best of Luck with making your forms Mafamba |
|
|
|
Sep 11 2006, 05:48 PM
Post
#4
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 1,002 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
Form are easiest to make with PHP, and that's how I prefer it.
Also, I made an error in my PHP syntax: in the IF conditions, the nubmers should be quoted - so it should be if (select == "0"). Told you it's not perfect |
|
|
|
Sep 11 2006, 09:05 PM
Post
#5
|
|
|
Absolute Newbie Group: Admin Posts: 887 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 |
It seems that a great deal of new web designers don't realize that 99% of web forms require some kind of handler script. This script can either be client side like JavaScript or server side like PHP, Perl, or Java.
In fact, the entire point of a form is to interface with a script. The only exception to this that I can think of is the mailto action. You can send a message to the email address specified in the action definition of the form. You cannot chose the email address you want to send to and you can only send the message body. All other email forms require a script to handle the data and pass it on in the email. Looks to me that the solution that pyost offered is a very good entry level solution for you. I suggest that you try to figure out how the script actually works and build on it. You will find a lot of support in the PHP forum if you wish to learn more about PHP and form handlers. vujsa |
|
|
|
Sep 12 2006, 12:23 AM
Post
#6
|
|
|
Premium Member Group: Members Posts: 292 Joined: 15-December 04 Member No.: 1,768 |
I just made this form in order to redirect me to the page selected by a user, but it doesn't do that, it just reload the entire page: CODE <form name="broker" action="?" method="get"> <select name"select"> <option value="" selected>Select one below...</option> <option value="http://www.msn.com">MSN</option> <option value="http://www.yahoo.com">Yahoo</option> </select> <input type ="submit" name="submit" value="Choose"> </form> i hope any body can help in this. Try this if you don't want to use php. I use this method a lot when dealing with forms. However it is not "foolproof", and if someone has javascript disabled it will not work. In other words, you shouldn't use it if you really need this to work for all of your users, but I like it myself. Perhaps both methods in action would be best. The php and the javascript. Use the Javascript if it's available, else use the PHP. CODE <form name="broker" action="?" method="POST"> <select name="select" onchange="if(this.selectedIndex){this.form.action=this.options[this.selectedIndex].value;this.form.submit();}"> <option value="" selected>Select one below...</option> <option value="http://www.msn.com">MSN</option> <option value="http://www.yahoo.com">Yahoo</option> </select> <input type="submit" value="Choose"> </form> In this case it submits automatically when selecting an option. Also note that I took off the name attribute of your submit button as it caused conflicts with the "this.form.submit()" function. If you want a quick explanation of the javascript's logic then it's if there is something selected then it will take the value of the selected field, put it as the action to the form, and submit the forum. As far as syntax go you should look into that yourself, but don't be afraid to ask questions. This post has been edited by minnieadkins: Sep 12 2006, 12:34 AM |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th September 2008 - 05:41 AM |