• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

Using form data as part of the form action

I have a small form that has a select input with group numbers for hotel reservations.  The action on the form is the hotel url, and I was trying to pass in the select value as the group number on the end of the url.  Below is the code I have written.

If it's not possible to use a $_POST[] variable in the action of the form itself, how should I do this?
<div id="weekendSelect">
	<h3>HOST HOTEL--DRURY INN & SUITES</h3>  
	<form id="womenHotel" name="womenHotel" method="post" action="http://www.druryhotels.com/Reservations.aspx?groupno=<?php echo $_POST['weekend']; ?>" >
		<select id="weekend" name="weekend">
		  <option value="" selected>Please select your weekend.</option>
		  <option value="2126301">March 10-11, 2012</option>
		  <option value="2126302">March 17-18, 2012</option>
		  <option value="2126304">March 24-25, 2012</option>
		  <option value="2126305">March 31-April 1, 2012</option>
		  <option value="2126308">April 14-15, 2012</option>
		  <option value="2126309">April 21-22, 2012</option>
		</select>
		<input name="View Rooms" type="submit" value="submit">
	</form>	
</div>

Open in new window

0
DennisHacker
Asked:
DennisHacker
  • 2
  • 2
  • 2
1 Solution
 
Scott MadeiraCommented:
I don't know the details of how to do it but I think you will need to use Javascript to build the URL you want to execute.  The $_POST[] variables won't exist until the form is submitted to the server at the URL in the action parameter.

One thing you could do would be to have your action script take in the all the form data, build the URL you want to go to and then do a redirect to the URL.

0
 
Scott MadeiraCommented:
Another way to do it if all you want to do is route them to a particular URL based on what they choose (no other variables on the form would be to build each option as a link and not a select list on a form.

for Example:

 
<p>
<a href="http://www.druryhotels.com/Reservations.aspx?groupno="2126302">March 17-18, 2012</a><br>
<a href="http://www.druryhotels.com/Reservations.aspx?groupno="2126304">March 24-25, 2012</a><br>
<a href="http://www.druryhotels.com/Reservations.aspx?groupno=2126305">March 31-April 1, 2012</a><br>
<a href="http://www.druryhotels.com/Reservations.aspx?groupno="2126308">April 14-15, 2012</a><br>
<a href="http://www.druryhotels.com/Reservations.aspx?groupno="2126309">April 21-22, 2012</a><br>
</p>

Open in new window

0
 
Sudaraka WijesingheWeb Application ProgrammerCommented:
In the example you have provided, groupno will be available to server side as HTTP GET and weekend will be available as HTTP POST.

I assume what you are trying to do is send the the selected weekend as the "groupno" parameter over HTTP GET. If so, try it this way.
<div id="weekendSelect">
        <h3>HOST HOTEL--DRURY INN & SUITES</h3>  
        <form id="womenHotel" name="womenHotel" method="get" action="http://www.druryhotels.com/Reservations.aspx" >
                <select id="weekend" name="groupno">
                  <option value="" selected>Please select your weekend.</option>
                  <option value="2126301">March 10-11, 2012</option>
                  <option value="2126302">March 17-18, 2012</option>
                  <option value="2126304">March 24-25, 2012</option>
                  <option value="2126305">March 31-April 1, 2012</option>
                  <option value="2126308">April 14-15, 2012</option>
                  <option value="2126309">April 21-22, 2012</option>
                </select>
                <input name="View Rooms" type="submit" value="submit">
        </form> 
</div>

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DennisHackerAuthor Commented:
smadeira:  I will take a look at your first solution.  Your second one is exactly what I'm trying to avoid.  I don't want six links for them to choose between.
0
 
DennisHackerAuthor Commented:
Excellent.  I added a target value to the form action so that the page opens in a new window.  Very nice.  It totally accomplishes what I was trying to do.
0
 
Sudaraka WijesingheWeb Application ProgrammerCommented:
Glad to help. Thanks for the points.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now