Avatar of DennisHacker
DennisHackerFlag for United States of America

asked on 

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

PHPHTML

Avatar of undefined
Last Comment
Sudaraka Wijesinghe
Avatar of Scott Madeira
Scott Madeira
Flag of United States of America image

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.

Avatar of Scott Madeira
Scott Madeira
Flag of United States of America image

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

ASKER CERTIFIED SOLUTION
Avatar of Sudaraka Wijesinghe
Sudaraka Wijesinghe
Flag of Sri Lanka image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of DennisHacker
DennisHacker
Flag of United States of America image

ASKER

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.
Avatar of DennisHacker
DennisHacker
Flag of United States of America image

ASKER

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.
Glad to help. Thanks for the points.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo