GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Dec-2006, 19:51
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Return to previous page.


Greetings and salutations this fine evening.

I have a easy question.


I have a form on my site, where visitors submit information into a database. Upon clicking the submit button, I want the user to be able to return to their previous page.

How might I do this.

Thanks,
Richard
  #2  
Old 03-Dec-2006, 05:21
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 741
admin will become famous soon enough

Re: Return to previous page.


There are obviously a couple of ways you could handle this and the easiest (I think) is to grab the referrer data when they fetch the form and paste it in into the form itself as a hidden form element.

PHP Code:

<?php

// FILENAME: the_form.php

if( $_POST )
{    // form submitted
    $success = process_form_data();
    
    // if $success, now we re-direct the user to the page he came from
    if( $success )
    {
        if( !$_POST['referredby'] ) // if there was no referer information, we redirect them to our homepage.
            $_POST['referredby'] = 'http://www.example.com/'; //i.e. our homepage.

        header( "Location: $_POST[referredby]" );
        exit;
    }
}
else
{    // show the form.
    echo '<form method="post" etc...>';
    
    // get referrer data.
    $referredby = null;
    if( isset($_SERVER['HTTP_REFERER'])  &&  $_SERVER['HTTP_REFERER'] )
        $referredby = htmlspecialchars( $_SERVER['HTTP_REFERER'] );
    
    echo '<input type="hidden" name="referredby" id="inputReferredBy" value="',
            $referredby,
            "\" />\n";
    echo "</form>\n";
}
?>

__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #3  
Old 04-Dec-2006, 18:39
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Re: Return to previous page.


I can see what you showing, but for some reason I can't seem to make it work for me.

I'm not very adept at PHP, so I can very easily be doing this wrong.


Thanks,
Richard
  #4  
Old 05-Dec-2006, 22:51
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 741
admin will become famous soon enough

Re: Return to previous page.


I will try to explain better, but not right away.

Meanwhile, can you show me what you have tried?
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
 
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Things to Avoid in C/C++ -- gets() , Part 1 WaltP C Programming Language 5 21-Jun-2007 12:13
need help with a console menu system BullBuchanan CPP / C++ Forum 6 20-Aug-2006 14:46
Reading non ASCII with read() Atomical C Programming Language 8 13-Sep-2005 14:30
Problem with one variable bretter CPP / C++ Forum 1 16-May-2005 07:20
C++ file I/O CronoX CPP / C++ Forum 36 09-Mar-2004 17:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:44.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.