Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> What's Wrong With This Form?
XIII
post Sep 11 2006, 03:56 AM
Post #1


Advanced Member
Group Icon

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
Go to the top of the page
 
+Quote Post
pyost
post Sep 11 2006, 07:52 AM
Post #2


Nenad Bozidarevic
Group Icon

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 smile.gif
Go to the top of the page
 
+Quote Post
Mafamba Team
post Sep 11 2006, 04:12 PM
Post #3


Advanced Member
Group Icon

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
Go to the top of the page
 
+Quote Post
pyost
post Sep 11 2006, 05:48 PM
Post #4


Nenad Bozidarevic
Group Icon

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 smile.gif
Go to the top of the page
 
+Quote Post
vujsa
post Sep 11 2006, 09:05 PM
Post #5


Absolute Newbie
Group Icon

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
Go to the top of the page
 
+Quote Post
minnieadkins
post Sep 12 2006, 12:23 AM
Post #6


Premium Member
Group Icon

Group: Members
Posts: 292
Joined: 15-December 04
Member No.: 1,768



QUOTE(XIII @ Sep 10 2006, 11:56 PM) *

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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Code To Send An Email From A Form(7)
  2. Favourite Bands(64)
  3. Whats The Last Dvd You Watch And Rate It Out Of 10(14)
  4. What's The Difference Between Linux And Unix?!?(15)
  5. What's The Best 3d Animation Software?(14)
  6. Cinema 4d Or 3d Studio Max(10)
  7. Server Os(13)
  8. The Best Metroid Game(10)
  9. Notebook Or Laptop?(16)
  10. Whats A High Quality Gaming PC Specs(15)
  11. Hardware Review Online... Whats The Best Site?(5)
  12. Perl Vs Php(13)
  13. Boast Your Computers Specs.(157)
  14. Whats A Good Graphics Editor For Solaris 10 ?(8)
  15. Who Is Your Favourite Free Host?(140)
  1. My Review Of Runescape... What's Yours ( Poll ) ?(66)
  2. PHP Tutorial: Form Verification And Simple Validation(12)
  3. Besides AVG, What's The Best Free Anti-Virus?(16)
  4. What's The Best CMS(35)
  5. 4 OS On One Computer(10)
  6. Cruzer Flash Drive (usb)(11)
  7. Whats The Ascii Code Of Your Name?(4)
  8. Rpg Maker Xp Questions(1)
  9. What's Wrong?(3)
  10. Request Form Site Suspended(4)
  11. Php Random Selector(2)
  12. Something Is Wrong When Linking (dev-c++)(2)
  13. Design A Contact Form In Flex Part 1(0)


 



- Lo-Fi Version Time is now: 8th September 2008 - 05:41 AM