Difficulty with multiple <form>s

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nightswore
Forum Newbie
Posts: 13
Joined: Thu May 15, 2008 11:26 am

Difficulty with multiple <form>s

Post by nightswore »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


So I'm working on this search function for a status page I've made. Basically it uses a little javascript to have the user select their input from a popup calendar. Not too difficult really, and not my problem. Once implimented however, I don't have a good way to submit the data in the fields they fill out because both fields require a <form> tag to complete their action, and because of this, I can't seem to put a <form> tag completely around the two statements so that I can then post the information with a submit button, once I put the <form> tag before the first javascript popup, it stops working and I have nothing to submit. The javascript looks like this (this is without the script commands in the header):

Code: Select all

   <td>Start Date :</td>
    <td>
    
    <FORM NAME="start">
<INPUT TYPE="text" NAME="date1" VALUE="" SIZE=25>
<A HREF="#"
   onClick="cal.select(document.forms['start'].date1,'anchor1','MM/dd/yyyy'); return false;"
   NAME="anchor1" ID="anchor1">Select</A>
</FORM></td>
<td>End Date :</td>
    <td>
    <FORM NAME="end">
<INPUT TYPE="text" NAME="date1" VALUE="" SIZE=25>
<A HREF="#"
   onClick="cal.select(document.forms['end'].date1,'anchor1','MM/dd/yyyy'); return false;"
   NAME="anchor1" ID="anchor1">Select</A>
</FORM></td>
 
So you can see that it starts with a form and then does a lot of javascript ten closes the form and then moves to the next object. What I need to do is somehow get both of those inputs tied to a submit button that would basically be where this code ends. If anyone has any tricks or ideas, I'd appreciate the input.

If any clarification is needed, I can provide some, I'm always bad at explaining my problem well, haha.


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
mabwi
Forum Commoner
Posts: 27
Joined: Wed Aug 01, 2007 4:51 pm

Re: Difficulty with multiple <form>s

Post by mabwi »

Is there any reason both javascript objects can't be in the same form? And they just write to different fields?
nightswore
Forum Newbie
Posts: 13
Joined: Thu May 15, 2008 11:26 am

Re: Difficulty with multiple <form>s

Post by nightswore »

The form names are part of what the script uses to process the information, that is why they're named 'start' and 'end'.

I tried it anyway and it didn't seem to like it, got a pop up warning message instead of my calendar.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Difficulty with multiple <form>s

Post by pickle »

Your <form> tags can't start in one cell & end in another - that might be your problem. Wrap that whole table in <form></form> tags & try to submit it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
nightswore
Forum Newbie
Posts: 13
Joined: Thu May 15, 2008 11:26 am

Re: Difficulty with multiple <form>s

Post by nightswore »

Yes...you...can? I do it all the time...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Difficulty with multiple <form>s

Post by pickle »

If you can, it's only because the browser you're using is smart enough to recover from bad coding practices. Try validating the source code of that page & see what happens.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
mabwi
Forum Commoner
Posts: 27
Joined: Wed Aug 01, 2007 4:51 pm

Re: Difficulty with multiple <form>s

Post by mabwi »

nightswore wrote:The form names are part of what the script uses to process the information, that is why they're named 'start' and 'end'.

I tried it anyway and it didn't seem to like it, got a pop up warning message instead of my calendar.
What if you renamed the elements within the form. Like so:

Code: Select all

 
 
<FORM NAME="calendarcontrol">
<table><tr>
<td>Start Date</td>
<td>
<INPUT TYPE="text" NAME="startdate" VALUE="" SIZE=25>
<A HREF="#"
   onClick="cal.select(document.forms['calendarcontrol'].startdate,'anchor1','MM/dd/yyyy'); return false;"
   NAME="anchor1" ID="anchor1">Select</A>
</td>
</tr><tr>
<td>End Date :</td>
    <td>
<INPUT TYPE="text" NAME="enddate" VALUE="" SIZE=25>
<A HREF="#"
   onClick="cal.select(document.forms['calendarcontrol'].enddate,'anchor2','MM/dd/yyyy'); return false;"
   NAME="anchor2" ID="anchor2">Select</A>
</td>
</tr></table>
</FORM> 
 
One form, two controls, each with a distinct name. This should work, unless the Javascript is doing something wacky.
nightswore
Forum Newbie
Posts: 13
Joined: Thu May 15, 2008 11:26 am

Re: Difficulty with multiple <form>s

Post by nightswore »

Thanks, but it got to the point where I jus found a different javascript, haha. Thanks though!
Post Reply