bookmark - How To Get Two Web-forms To Work Together ?

How To Get Two Web-forms To Work Together ?

 
 Discussion by NewGuyinTown with 7 Replies.
 Last Update: February 20, 2006, 8:37 pm
 
bookmark - How To Get Two Web-forms To Work Together ?  
    
free web hosting
 
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.

Sun Feb 19, 2006    Reply    New Discussion   


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.

Sun Feb 19, 2006    Reply    New Discussion   

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.

Sun Feb 19, 2006    Reply    New Discussion   

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?

Sun Feb 19, 2006    Reply    New Discussion   


QUOTE (Houdini)


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?

Link: view Post: 70531

;) I didn't even know there was a closing tag for a form... B)
Sorry... not completely familiar with the language.

Sun Feb 19, 2006    Reply    New Discussion   

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.

Sun Feb 19, 2006    Reply    New Discussion   

QUOTE (NewGuyinTown)


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.
Link: view Post: 70528

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)


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.

Link: view Post: 70528

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.

Mon Feb 20, 2006    Reply    New Discussion   

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.

Mon Feb 20, 2006    Reply    New Discussion   

Quickly Post to How To Get Two Web-forms To Work Together ?  w/o signup Share Info about How To Get Two Web-forms To Work Together ?  using Facebook, Twitter etc. email your friend about How To Get Two Web-forms To Work Together ? Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Need HTML Positioning Help   Need HTML Positioning Help (2) (2) Need Help Fixing My Logo   Need Help Fixing My Logo