Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Sending Forms with GET variables from other forms (http://www.programmingforums.org/showthread.php?t=15259)

MrMan9879 Feb 25th, 2008 10:50 PM

Sending Forms with GET variables from other forms
 
Hi guys, I have another question... this time about using forms and the $_GET method.

Basically, for the website I'm building I have a news posting system, and I want to have a page where you can edit the posts. When you go to the editing page, I want to be able to order it by ID or title name.

My editing page is on my index.php, but I have a few pages on there, and I use a $_GET variable to get to them.
ie. index.php?act=post index.php?act=edit

I'm also using a $_GET variable for ordering the news articles to edit/delete
ie. index.php?act=edit&sort=newsdesc

But, I'm wondering how I can send the form that holds the sort variable to the page and also keep the act variable. I thought it might be as simple as this:

:

<form action="index.php?act=edit" method="get">
                <input type="radio" name="sort" value="newsdesc" />
          </form>


But, all this does is send it to index.php.

Does anyone know how I could accomplish this?

kruptof Feb 26th, 2008 7:43 AM

Re: Sending Forms with GET variables from other forms
 
Quote:

Originally Posted by MrMan9879 (Post 141572)
:

<form action="index.php?act=edit" method="get">
<input type="radio" name="sort" value="newsdesc" />
 </form>


You could use a hidden field set it's value to the action, or just stick it in the $_SESSION array.

:

<form action="index.php?act=edit" method="get">
                <input type="radio" name="sort" value="newsdesc" />
                <input type="hidden" name="action" value="<?php print $_GET['action']" />
          </form>


Ooble Feb 26th, 2008 7:56 AM

Re: Sending Forms with GET variables from other forms
 
Little tip: never just chuck out unescaped user input. Try this:
:

<input type="hidden" name="action" value="<?php echo htmlspecialchars($_GET['action']) ?>" />

MrMan9879 Feb 26th, 2008 10:04 PM

Re: Sending Forms with GET variables from other forms
 
Wow, I must have been tired last night... I'm not sure why that didn't occur to me.

Thanks for your help again, Ooble.

Ooble Feb 27th, 2008 4:47 AM

Re: Sending Forms with GET variables from other forms
 
Methinks it was kruptof that gave you the solution. I just expanded on it a little.

MrMan9879 Feb 27th, 2008 9:11 PM

Re: Sending Forms with GET variables from other forms
 
Oh sorry, Kruptof I just read the bottom post and for some reason assumed it was Ooble both times.


All times are GMT -5. The time now is 9:40 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC