dtyson2000 Posted December 17, 2006 Share Posted December 17, 2006 Hi all...I'm having a bit of a hard time with something that seems like it should be simple. Here goes:I would like to use a form to have a user input a zip code that would (upon clicking submit) be inserted into the middle of a URL that has constants on both sides and then they should be directed to that URL.I've got definitions for both sides of the URL set as "const1 and const2"...I've got my form, the action on which I've only gotten close with ACTION="$const1$userzip$const2" METHOD="post"The field in the form is named "userzip"... So the current result is to direct me to the new url minus the userzip.make sense?Here's the code:[code]// driving direction link$const1 = "http://maps.google.com/maps?saddr=";$const2 = "&daddr=27%20Main%20St%20+90210&hl=en";echo "<table align='center' style='background-color:#eeeeee;'> <tr> <td align='center'>Need Directions?<br>Just put your zip code in the box below.</p></td> </tr> <tr> <td align='center'> <form name='form' action='$const1$userzip$const2' method='post'> <input type='text' size='11' name='userzip' value='Your Zip Code'> <input type='submit' name='submit' value='Get Directions'> </form></td> </tr> </table>";[/code]Thanks, in advance! Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/ Share on other sites More sharing options...
drifter Posted December 17, 2006 Share Posted December 17, 2006 for this, you can either post back to the form, read the variables in and then use header("location: $newurl");or you can have the form use an onclick in javascript - then read the field and assemble the URL and then send you there. Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143089 Share on other sites More sharing options...
doni49 Posted December 17, 2006 Share Posted December 17, 2006 Personally, I'd prefer the first suggestion myself. I don't like depending on the user to have javascript enabled--and what about if they're on a device that doesn't even have javascript? Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143094 Share on other sites More sharing options...
dtyson2000 Posted December 17, 2006 Author Share Posted December 17, 2006 [quote author=drifter link=topic=119011.msg486803#msg486803 date=1166388415]for this, you can either post back to the form, read the variables in and then use header("location: $newurl");or you can have the form use an onclick in javascript - then read the field and assemble the URL and then send you there.[/quote]Post back to the form? I'm not sure what you mean.I would definitely like to stay away from javascript. If a user doesn't have it turned on, that puts the screws to that... Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143112 Share on other sites More sharing options...
Submerged Posted December 17, 2006 Share Posted December 17, 2006 Hmmmm.. I was actually just about to post this question. I think I could manage to do it using js, but it would be better to stay away from that if possible. but can you do it w/o javascript, and without refreshing/redirecting the page prior to the end page link? Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143117 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Share Posted December 17, 2006 on a page called redirect1.php[code]<table align='center' style='background-color:#eeeeee;'> <tr> <td align='center'>Need Directions?<br>Just put your zip code in the box below.</p></td> </tr> <tr> <td align='center'> <form name='form' action='redirect2.php' method='post'> <input type='text' size='11' name='userzip' value='Your Zip Code'> <input type='submit' name='submit' value='Get Directions'> <input type="hidden" value="http://maps.google.com/maps?saddr=" name="const1"> <input type="hidden" value="&daddr=27%20Main%20St%20+90210&hl=en" name="const2"> </form></td> </tr> </table>[/code]and then on a page called redirect2.php[code]<?phpob_start();$zip = $_POST['userzip'];$const1 = $_POST['const1'];$const2 = $_POST['const2'];header("Location: ".$const1."".$zip."".$const2);ob_end_flush()?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143120 Share on other sites More sharing options...
Submerged Posted December 17, 2006 Share Posted December 17, 2006 Well, if you are going to redirect, i would just leave javascript out of redirect2.php and just go with a simple meta refresh:redirect2.php[code]<?$zip = $_POST['userzip'];$const1 = $_POST['const1'];$const2 = $_POST['const2'];echo "<meta http-equiv=\"refresh\" content=\"0;url=$const1$zip$const2\">";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143122 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Share Posted December 17, 2006 header(); is php.<script>header="";</script>that is javascript Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143125 Share on other sites More sharing options...
dtyson2000 Posted December 17, 2006 Author Share Posted December 17, 2006 Excellent.... Thanks to both of you (JP128 & Submerged)!JP128: I used your advice for two files. The first file with the form and the hidden values was perfect. In fact, I was thinking about hidden values but am not that proficient yet to know exactly what to do with them. The second file kept giving me a parse error.Submerged: I used your meta-refresh in the second file and it worked perfectly.There's our solution. The JP128/Submerged method.Thanks, again! Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143140 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Share Posted December 17, 2006 Well, glad we could help. Quote Link to comment https://forums.phpfreaks.com/topic/31011-solved-form-submit-value-go-to-url/#findComment-143153 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.