html forms, php and http redirects?

Status
Not open for further replies.
I currently do a basic php form parsing process:
1. html form
2. send to script on seperate page
3. http redirect to where I want to send the user after that based on form results.

what are my options to remove the intermediate page but still have the server-side code run?

is there some sort of javascript I can add to the form that would call the resulting page in the background and any redirect reloads the browser window, basically hiding the intermediate page? said code should have some sort of token "processing" text or image.
 

bdr

Wise, Aged Ars Veteran
137
I don't see the problem.

The user should never see your intermediate page if you're doing correct http-redirects. That is, you can redirect a user after any kind of server side processing as long as you make sure that the preceding php-code never outputs anything, even not a single space or carriage return (this might be your problem).

You could create an AJAX version that does what you want, but you will still need your current code for those without javascript.
 
I should clarify, by http redirects I mean a meta refresh. Am I wrong that true redirects in php are for when a page no longer exists?

the intermediate page has to load to do the processing. thus it shows. it's what I want to hide.

any non-javascript options? how about an iframe? can a meta refresh target the parent page?

so basically, it would be my processing code followed by the php refresh command? it won't even show the processing page?
 

theFinn

Ars Tribunus Militum
2,705
Subscriptor++
Yeah, like bdr said you want to do the redirect using an HTTP header rather then the method you're using with a meta refresh.

Basiclly your form posts to a PHP script that doesn't output anything, it does whatever logic you want it to do then issues an HTTP header.

ie:
Code:
<?php

db_submit($_REQUEST['form_data']);
header('Location: http://mysite.com/my_result_page.html');

?>

The intermediary page will never show. One thing to keep in mind is that your script can output NOTHING before the header or it'll throw an error.

see: http://php.net/manual/en/function.header.php
 
Status
Not open for further replies.