Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> How To Get Two Web-forms To Work Together ?
NewGuyinTown
post Feb 19 2006, 01:45 PM
Post #1


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 16
Joined: 15-February 06
Member No.: 11,304



Does anyone know how to get two forms to work?

I have a login on the navigation bar and a commenting box on the middle table.
However, the sumbit button in the commenting box responds the login form.

If not, is there a way to get something like this to work: A login and a commenting box.

This post has been edited by miCRoSCoPiC^eaRthLinG: Feb 19 2006, 04:34 PM
Go to the top of the page
 
+Quote Post
szupie
post Feb 19 2006, 03:27 PM
Post #2


S.P.A.M.S.W.A.T.
Group Icon

Group: Members
Posts: 814
Joined: 22-January 05
From: San Antonio, Texas (No, I'm not dumb. I just moved here...)
Member No.: 2,284



Can you give us an example of what your site looks like. I think it might be possible to put your table inside one form to make the coding easier.

However, if that's not possible, you could use javascript to combine 2 forms into one. Since normal pages won't accept 2 forms at once, you can create a third form that's hidden from the user, and it will take the data from the 2 forms and submit it as one.

First, create a hidden form where you want the submit button to be. The visitors will only be able to see the submit button, not the inputs.
CODE
<form name="hidForm" action="the page you want to submit the data to" method="post/get" onsubmit="return submitForm();">

<input type="hidden" name="value1" />
<input type="hidden" name="value2" />
<input type="hidden" name="value3" />
<input type="hidden" name="value4" />
...
<input type="submit" />

</form>


I'll assume that your other 2 forms have the names "form1" and "form2" (<form name="form1"> and so on). They should not have submit buttons.

Then, for the javascript code:
CODE
function submitForm() {
  var hiddenForm = document.hidForm;
  var form1 = document.form1;
  var form2 = document.form2;

  hiddenForm.value1 = form1.value1;
  hiddenForm.value2 = form1.value2;
...
  hiddenForm.value5 = form2.value1;
  hiddenForm.value6 = form2.value2;
  hiddenForm.value7 = form2.value3;
}

This code will take all the data and put them in the hidden form before it is submitted. If there is an error in the script, it will not submit.

Of course, the names for the inputs of the hidden form can be changed to a more descriptive name. I'm just giving you the basic idea for how to do this.
Go to the top of the page
 
+Quote Post
NewGuyinTown
post Feb 19 2006, 05:44 PM
Post #3


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 16
Joined: 15-February 06
Member No.: 11,304



Click here to see the webpage
I removed the login form, so now the login does not work...

I could combine it as one, but then it would mean that the sumbit button takes you to one page. I don't know if it is a good idea to combine verifylogin.php, addcomment.php, sumbitapplication.php, etc. all into one page as well.

I want it as two separate forms, but the sumbit button respond to the wrong forms. The only way I can think of getting this to work is to have a function that sets a variable to the url of the nextpage and have:
<form method="post" action=$next>
I don't think that is going to work.

Also I do not like the idea of a static amount of hidden textboxes. What if I need 100 when there is 60? What if I need 9000 when there is only 100? I was wondering if there is a way to generate hidden textboxes without refreshing.
Go to the top of the page
 
+Quote Post
Houdini
post Feb 19 2006, 06:19 PM
Post #4


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340



It sounds to me that the login form was never closed and the other one was so it confused the whole thing do you have the code for the login form all by itself?
Go to the top of the page
 
+Quote Post
NewGuyinTown
post Feb 19 2006, 06:32 PM
Post #5


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 16
Joined: 15-February 06
Member No.: 11,304



QUOTE(Houdini @ Feb 19 2006, 06:19 PM) *

It sounds to me that the login form was never closed and the other one was so it confused the whole thing do you have the code for the login form all by itself?

laugh.gif I didn't even know there was a closing tag for a form... dry.gif
Sorry... not completely familiar with the language.
Go to the top of the page
 
+Quote Post
Houdini
post Feb 19 2006, 06:38 PM
Post #6


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340



Your login wil simply not work with the code that you have and the comment form is incomplete as well. Here is what I saw viewing your page source:
CODE
<tr>
<td align="left" valign="top" width="150" height="100%">
     <font size="2">
     <b>Login:</b><br />

     Username:<br />
     <input type="text" name="username" size="15"><br />
     Password:<br />
     <input type="password" name="pass" size="17"><br />
     <input type="button" value="Login"><br />
     <div align="right"><font size="1px"><a href="registration.php">Register</a></font></div>

There needs to be a form for that to work, the browser merely sees a text box input for a user name and then there is a password input box also, but there is no form tag as in <form action="login.php" method="post> and a button with the value Login (it should be a submit button with a value of login that button will not do anything. Then you would need to close the form with </form>

Then at least you have the beginnings of a form for the comments and it may or may not work, but the login as pointed out above definately won't. The code for the comment box that is shown on the site also need to have a closing tag for the form as in </form> normally right after the submit button. Try fixing the first form and give it a script to be executed with after someone enters a username and password. Your form will need to check against a database or flat file to check the username and all for the login to ever have a hope of working.
Go to the top of the page
 
+Quote Post
szupie
post Feb 20 2006, 04:32 PM
Post #7


S.P.A.M.S.W.A.T.
Group Icon

Group: Members
Posts: 814
Joined: 22-January 05
From: San Antonio, Texas (No, I'm not dumb. I just moved here...)
Member No.: 2,284



QUOTE(NewGuyinTown @ Feb 19 2006, 11:44 AM) *

I could combine it as one, but then it would mean that the sumbit button takes you to one page. I don't know if it is a good idea to combine verifylogin.php, addcomment.php, sumbitapplication.php, etc. all into one page as well.

You could create a process.php that processes all the data from the forms, and then distributes them to the appropriate pages. You can use the include() statement to do that.

QUOTE(NewGuyinTown @ Feb 19 2006, 11:44 AM) *

Also I do not like the idea of a static amount of hidden textboxes. What if I need 100 when there is 60? What if I need 9000 when there is only 100? I was wondering if there is a way to generate hidden textboxes without refreshing.

When I was writing the code, I was disgusted by the idea of static and repetitive input boxes too. But I couldn't come up with a better way to do it. You can use PHP to generate the input boxes, but I don't have any good ideas on how to do that. My mind is too clouded right now.
But under what circumstances will your number of input boxes suddenly change? Shouldn't it be the same every time? I agree that a static amount of boxes is bad coding, but I still want to know what you were talking about.
Go to the top of the page
 
+Quote Post
minnieadkins
post Feb 20 2006, 08:37 PM
Post #8


Premium Member
Group Icon

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



You could have all as one form. I don't think you can embed a form inside another form. I think it defaults back to the action of your first form. Although you can use javascript to change the action of your form, so one form would be sufficient.

CODE

<form>
<div id="login">
<!-- login module goes here -->
LOGIN:
<input's />
<input type="submit" onclick="this.form.action='./login/validatelogin.php';" />
</div>
<div id="content">
<!-- main content of page goes here...which can be form items -->
POLL:
Choose option:
<select><options></select>
<input type="submit" onclick="this.form.action='./content/votepoll.php';" />
</div>
</form>

Just requires a little clientside overhead, but everything should work just fine, might have a few variables hanging around that shouldn't be there in the $_POST or $_GET arrays. Was just a thought.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How Do You Create Web-Forms?(8)
  2. Advanced Form Question(0)


 



- Lo-Fi Version Time is now: 1st December 2008 - 08:50 PM