PHP forms

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
Paul-sea
Forum Newbie
Posts: 6
Joined: Tue Dec 02, 2014 12:18 am

PHP forms

Post by Paul-sea »

Hi

I am a relative newbie to PHP

Although I am familiar with creating web forms in PHP, could someone suggest a method for the following:

I have three web pages (page 1, page 2, page 3) , each page relates to a different subject all the pages can access a contact form, I need to add a subject line to the form which can be populated by a variable from page 1, 2 or 3 dependant on which page the form is accessed from.

I realize I could generate 3 individual forms to do this, but my page count is likely to increase significantly in the future so it makes sense to use variables to populate the subject line.

Please advise!

Paul C
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP forms

Post by requinix »

It depends mostly on what you already have. Are those three pages and the contact form already written?
Paul-sea
Forum Newbie
Posts: 6
Joined: Tue Dec 02, 2014 12:18 am

Re: PHP forms

Post by Paul-sea »

Hi requinix

Nothing written as yet so ..... clean sheet..... I have created contact forms on a couple of web sites in the past, but this is slightly different. essentially each page will have a "contact us for more info" button to open the form. The actual form php I already have and can adapt, its just the best method to pass a string from the chosen page to the form. I am in no way a programmer or coder but I am willing to learn what I need to in order to achieve this!!

Please advise

Thanks!! :-)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP forms

Post by Celauran »

Where is the page content coming from? Is it CMS-driven or is it static? Passing a variable to the form is trivial, but the value still needs to be obtained somewhere.
Paul-sea
Forum Newbie
Posts: 6
Joined: Tue Dec 02, 2014 12:18 am

Re: PHP forms

Post by Paul-sea »

Hi Celauran

Page will be static.
The string I need to pass to the form will be a product name.

Thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP forms

Post by Celauran »

If the page is static and you're just going to include() the form, you may as well just hardcode the variable value into each individual page.
Paul-sea
Forum Newbie
Posts: 6
Joined: Tue Dec 02, 2014 12:18 am

Re: PHP forms

Post by Paul-sea »

Hi Celauran

Yes understood on that, so each page will have a statement which goes along the lines of declaring $product="a unique product" (the $product value changes on each page). the advice I'm after is which method I need to employ to pass $product to the form. As stated I'm not a programmer, I just need to be pushed in the right direction :-)

Regards

PaulC
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP forms

Post by Celauran »

How are you including the form in the page?
Paul-sea
Forum Newbie
Posts: 6
Joined: Tue Dec 02, 2014 12:18 am

Re: PHP forms

Post by Paul-sea »

Hi Celauran

the form will be a separate page, only called if required by the user. and yes I've just had the lightbulb moment that says each page could be designed with the form embedded, which would negate the requirement to pass info between the web pages and a separate form.... but if I had to have a stand alone form, what would I need to do?

Regards

PaulC
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP forms

Post by Celauran »

Code: Select all

include '/path/to/form';
You won't need to do anything special to make the variable available to the form, just be sure to declare if before including the form.
Paul-sea
Forum Newbie
Posts: 6
Joined: Tue Dec 02, 2014 12:18 am

Re: PHP forms

Post by Paul-sea »

Celauran

Thanks, I'll go do some homework now....

Regards

Paul C
Post Reply