Jump to content
xisto Community
Sign in to follow this  
XIII

What's Wrong With This Form?

Recommended Posts

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:

 

<form name="broker" action="?" method="get">  <select name"select">	<option value="" selected>Select one below...</option>	<option value="http://http://www.msn.com/de-de?rd=1&ucc=DE&dcc=DE&opt=0;	<option value="http://yahoo.com/;  </select><input type ="submit" name="submit" value="Choose"></form>

i hope any body can help in this.
Edited by XIII (see edit history)

Share this post


Link to post
Share on other sites

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

 

<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

 

<?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://forums.xisto.com/no_longer_exists/; );	} else {		header( 'Location: http://forums.xisto.com/no_longer_exists/; );	}}?>

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 :)

Share this post


Link to post
Share on other sites

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 formsMafamba

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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:

 

<form name="broker" action="?" method="get">  <select name"select">	<option value="" selected>Select one below...</option>	<option value="http://http://www.msn.com/de-de?rd=1&ucc=DE&dcc=DE&opt=0;	<option value="http://yahoo.com/;  </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.

 

<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://http://www.msn.com/de-de?rd=1&ucc=DE&dcc=DE&opt=0;	<option value="http://yahoo.com/;  </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.

Edited by minnieadkins (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.