Jump to content

[SOLVED] $_GET problems


newbtophp

Recommended Posts

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

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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  :D

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.