Question about submitting a form through php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stacks
Forum Newbie
Posts: 24
Joined: Thu Jun 05, 2008 7:52 pm

Question about submitting a form through php code

Post by Stacks »

How would I go about this. What I want to do is have a user submit a form which is a search. I want to take that to a intermediate page to do a bunch of logic on the form input. From that intermediate page I want to resubmit it through PHP code to a results page.

Code: Select all

		<form enctype="multipart/form-data" id="grandSearch" name="grandSearch" action="grandSearch.php" method="post">
		                        <input type="text" name="grandSearch" value="Type your City Name here" />			
					<input class="button" type="submit" value="Submit" />
                </form>
I then want to process the data of this form. Have it ran through a series of logic. Depending on how I process this data I want to re-post the data to a new searchResults page. So can I create a form through PHP code and submit it? I almost want to say I want the php code to fake a user inputted form.

If you can just point me in the right direction I will be very grateful. Thank you.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Question about submitting a form through php code

Post by AbraCadaver »

To get each intermediate page to post you'll have to use javascript to do the posting on the intermediate pages. The better approach would be to use sessions or redirects with get vars:

formpage.php

Code: Select all

<html>
//your form to post
</html>
grandSearch.php

Code: Select all

$term=$_POST['grandSearch'];
//do stuff
header("Location: http://www.yoursite.com/next.php?term=$term");
exit;
next.php

Code: Select all

$term=$_GET['term'];
//do stuff
header("Location: http://www.yoursite.com/finished.php?term=$term");
exit;
finished.php

Code: Select all

$term=$_GET['term'];
//do stuff
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Stacks
Forum Newbie
Posts: 24
Joined: Thu Jun 05, 2008 7:52 pm

Re: Question about submitting a form through php code

Post by Stacks »

Thanks for the reply. I wanted to avoid using redirects and query strings. So you are telling me there is no way to fake a form submission?

I am almost certain there must be some kind of way to do this through the request object.

I'm looking into using the HTTPREQUEST object. Maybe I can fake a form post with this. If I figure it out I will post back here.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Question about submitting a form through php code

Post by John Cartwright »

PHP reside server side. To make requests on behalf of the client you must use a client side language, such as javascript.

If you don't care about whether the request comes from the client or the server, then take a look at cURL
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Question about submitting a form through php code

Post by AbraCadaver »

Stacks wrote:Thanks for the reply. I wanted to avoid using redirects and query strings. So you are telling me there is no way to fake a form submission?

I am almost certain there must be some kind of way to do this through the request object.

I'm looking into using the HTTPREQUEST object. Maybe I can fake a form post with this. If I figure it out I will post back here.
You can post with PHP but the browser won't redirect to the resultant page. I assume since you talked about a results page that you would need the browser to redirect there. Check this: viewtopic.php?f=1&t=113435&p=595834#p595847
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply