need help, newbie to php want to implement form.

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
dxplus
Forum Newbie
Posts: 1
Joined: Wed Mar 28, 2007 11:18 am

need help, newbie to php want to implement form.

Post by dxplus »

hello,

i have a 3 form in my site in different pages, let's say page1.php, page2.php and page3.php.

the form method is set to post, and action is set to processform.php

what i would like to ask here (coding the processform.php)

since the form is basically similar (sending an email but using fixed different destination).

1. how i detect from which page processform.php invoked (page1.php, page2.php, or page3.php) ?
so i can use if statement to process send email to different email address for each page.

2. how do i redirect and use "post" or "get" method back from processform.php to invoker page? so i can return an error message or successful message. (or maybe in php there is common technique to applying my needs here?)

thank you , please help.
lewmur
Forum Newbie
Posts: 4
Joined: Mon Mar 19, 2007 12:29 pm

Re: need help, newbie to php want to implement form.

Post by lewmur »

dxplus wrote:hello,

i have a 3 form in my site in different pages, let's say page1.php, page2.php and page3.php.

the form method is set to post, and action is set to processform.php

what i would like to ask here (coding the processform.php)

since the form is basically similar (sending an email but using fixed different destination).

1. how i detect from which page processform.php invoked (page1.php, page2.php, or page3.php) ?
so i can use if statement to process send email to different email address for each page.

2. how do i redirect and use "post" or "get" method back from processform.php to invoker page? so i can return an error message or successful message. (or maybe in php there is common technique to applying my needs here?)

thank you , please help.
The easiest way would be to have two processform.php pages. Have one input page call processform1.php and the other processform2.php. Then make the appropriate changes to processform2.php to reflect the destination and error return form.

Of course you could put a hardcoded varible in each calling form and then use if- else in the one called form. But that seems like the hard way to me.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

In the pages that have the form, enter a hidden field that is called refering_page, then add the name of the page that the form is on to that field.

Code: Select all

<input type="text" name="refering_page" value="<?php echo basename($_SERVER['SCRIPT_FILENAME']); ?>" />
Post Reply