Page 1 of 1
Question about submitting a form through php code
Posted: Thu May 06, 2010 11:22 am
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.
Re: Question about submitting a form through php code
Posted: Thu May 06, 2010 12:19 pm
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
Re: Question about submitting a form through php code
Posted: Tue May 11, 2010 3:44 pm
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.
Re: Question about submitting a form through php code
Posted: Tue May 11, 2010 3:49 pm
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
Re: Question about submitting a form through php code
Posted: Tue May 11, 2010 3:55 pm
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