newbtophp Posted August 10, 2009 Share Posted August 10, 2009 I have a form which functions and executes when I click submit. But I was wondering if theirs a way I can make it also work by url like: mysite.com/form.php?urls=http://www.phpfreaks.com and then when I access that link the form executes/submits and displays the result, as if the submit button was clicked. form.php <form action="" method="post"> <p align="center">[b]<textarea rows="10" cols="50" name="urls"></textarea>[/b]<br /></p> <p align="center">Display: <input type="checkbox" value="d" name="d" /> Mask: <input type ="checkbox" value ="1" name="go" /><br /></p> <p align="center"><input type="submit" name="submit" /> </p> </form> Thanks for you help Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/ Share on other sites More sharing options...
oni-kun Posted August 10, 2009 Share Posted August 10, 2009 If you use the GET, it wouldn't submit the form but go straight to the PHP code.. Something like this.. if (isset($_GET['urls'])) { //Redirect to URLS header('Location: '. $_GET['urls']); //Or do anything else.. display result etc. //echo 'URLS = ' . $_GET['urls']; } That means, if the url=http://www.site.com is filled, then it'll go to site.com or whichever function you wished for it to do.. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895180 Share on other sites More sharing options...
nankoweap Posted August 10, 2009 Share Posted August 10, 2009 if i understand what you're asking, there's no reason you can't. just use $_REQUEST (rather than $_GET) to access the form's variables. of course, you could change the method of the form to GET and just use $_GET or $_REQUEST. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895185 Share on other sites More sharing options...
newbtophp Posted August 10, 2009 Author Share Posted August 10, 2009 I think I've confused you, sorry. Let me brake it down. So if i enter: url=http://www.site.com It will enter site.com the in the below text area: <textarea rows="10" cols="50" name="urls"></textarea> Then submit: <input type="submit" name="submit" /> If theirs a better way of doing it then $_GET, then please tell me Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895187 Share on other sites More sharing options...
oni-kun Posted August 10, 2009 Share Posted August 10, 2009 You mean like this? <textarea rows="10" cols="50" name="urls"><?php echo $_GET['urls']; ?></textarea> I don't believe you can fill it in and submit it, atleast not with PHP. You'll need JS to submit the form onLoad().. Why do you need that form to be filled and sent with $_GET[]? You can just handle whatever the form does directly via PHP. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895188 Share on other sites More sharing options...
newbtophp Posted August 10, 2009 Author Share Posted August 10, 2009 $_GET is not neccesary, I have used it before theirfore I thought I'd use it, but it harder then i thought. Any better ways to accomplish this? or any javascript i can use Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895189 Share on other sites More sharing options...
oni-kun Posted August 10, 2009 Share Posted August 10, 2009 I'm really not sure what you're trying to do. But lets break it down to what I know.. <?php //If FORM was sent if (!isset($_GET['urls']) && isset($_POST['urls'])) { echo "URLS is $_POST['urls']" ; } else { echo "URLS is set through GET: $_GET['urls']"; } What is important about it being passed through the form? The above code will get it if the user .. A) Uses the form, or B) Arrives through a $_GET[] url.. everything can be handled through php. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895196 Share on other sites More sharing options...
newbtophp Posted August 10, 2009 Author Share Posted August 10, 2009 Being passed through the form is uneeded. My aim is to have 2 options to make it work by url and form. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895198 Share on other sites More sharing options...
oni-kun Posted August 10, 2009 Share Posted August 10, 2009 Yes, then my code is what you should use. It checks to make sure.. if the '?urls=' isn't used, then the form must be. Or if the '?urls=http://www.site.com' then it bypasses the form and does whatever you wish it to. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895199 Share on other sites More sharing options...
newbtophp Posted August 10, 2009 Author Share Posted August 10, 2009 So this is the overall code? <?php //If FORM was sent if (!isset($_GET['urls']) && isset($_POST['urls'])) { echo "URLS is $_POST['urls']" ; } else { echo "URLS is set through GET: $_GET['urls']"; } ?> <form action="" method="post"> <p align="center">[b]<textarea rows="10" cols="50" name="urls"></textarea>[/b]<br /></p> <p align="center">Display: <input type="checkbox" value="d" name="d" /> Mask: <input type ="checkbox" value ="1" name="go" /><br /></p> <p align="center"><input type="submit" name="submit" /> </p> </form> I get "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING" Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895202 Share on other sites More sharing options...
oni-kun Posted August 10, 2009 Share Posted August 10, 2009 <?php //If FORM was sent if (!isset($_GET['urls']) && isset($_POST['urls'])) { //DoSomething with $_POST[]'s variable here } elseif (isset($_GET['urls'])) { //DoSomething with $_GET[]'s variable here } else { //Nothing submitted. } ?> <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method="post"> <p align="center">[b]<textarea rows="10" cols="50" name="urls"></textarea>[/b]<br /></p> <p align="center">Display: <input type="checkbox" value="d" name="d" /> Mask: <input type ="checkbox" value ="1" name="go" /><br /></p> <p align="center"><input type="submit" name="submit" /> </p> </form> Works fine. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895208 Share on other sites More sharing options...
newbtophp Posted August 11, 2009 Author Share Posted August 11, 2009 I added the code. But when i access by url like: form.php?urls=http://www.site.com the form don't execute it just displays the form as if the url aint submitted. Whereas if i just paste the url in the textarea and submit it will execute. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895211 Share on other sites More sharing options...
oni-kun Posted August 11, 2009 Share Posted August 11, 2009 You need to add the code for the GET to do anything.. <?php //If FORM was sent if (!isset($_GET['urls']) && isset($_POST['urls'])) { //DoSomething with $_POST[]'s variable here } elseif (isset($_GET['urls'])) { $urls = $_GET['urls']; echo $urls; //use the same code you use for $_POST['urls'].. } else { //Nothing submitted. } ?> <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method="post"> <p align="center">[b]<textarea rows="10" cols="50" name="urls"></textarea>[/b]<br /></p> <p align="center">Display: <input type="checkbox" value="d" name="d" /> Mask: <input type ="checkbox" value ="1" name="go" /><br /></p> <p align="center"><input type="submit" name="submit" /> </p> </form> Submitting it is the equivilent of a GET, just not visible in the url. It works. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895214 Share on other sites More sharing options...
newbtophp Posted August 11, 2009 Author Share Posted August 11, 2009 Still the same, what am i doing wrong? Your code if i use url, it just echos the url on the page. It dont show whats executed when submitted. "You need to add the code for the GET to do anything.." Where do i add that.? Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895217 Share on other sites More sharing options...
newbtophp Posted August 11, 2009 Author Share Posted August 11, 2009 a better way to solve the problem is to have autosubmit when form.php?urls=http://www.site.com is used, we've figured out a way to input the urls in the textarea but not submit. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895256 Share on other sites More sharing options...
oni-kun Posted August 11, 2009 Share Posted August 11, 2009 a better way to solve the problem is to have autosubmit when form.php?urls=http://www.site.com is used, we've figured out a way to input the urls in the textarea but not submit. Please, explain your application and what you want to do with it, I'm profoundly unaware of what you exactly want. If you're wanting to submit the url that is in $_GET['urls'], then DONT use the form. Use PHP to submit it. if (isset($_GET['urls'])) { // Check if 'urls' exists in address $url = htmlspecialchars(escape($_GET['urls'])); //urls=http://www.example.com/ mysql_query(UPDATE Tables bla bla $url); //Use the $_GET['urls'] and ignore form echo 'Thank you for updating!'; // Result, no need for an 'auto-submit' } else { $url = htmlspecialchars(escape($_POST['urls'])); //If there is no GET, This is what the user submits from the form. mysql_query(UPDATE Tables bla bla $url); //Use the $_POST['urls'] and use form echo "Your submit was complete. Thank you for updating!"; } I don't get why you want it to 'auto-submit'.. submitting is for the user to enter something into the box and send to the php form..if you're wanting to submit what the GET url is, then the form isn't needed. You can skip the form, and update it directly like the code I just showed.. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895280 Share on other sites More sharing options...
newbtophp Posted August 11, 2009 Author Share Posted August 11, 2009 Thanks that finally solved it!!!!!!!!!!!!!!!!!!!!!!!!! :D :D :D Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895287 Share on other sites More sharing options...
oni-kun Posted August 11, 2009 Share Posted August 11, 2009 Thanks that finally solved it!!!!!!!!!!!!!!!!!!!!!!!!! :D :D :D No problem! Remember to mark this topic as solved. Quote Link to comment https://forums.phpfreaks.com/topic/169692-solved-_get-problems/#findComment-895291 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.