Forum Moderators: coopster

Message Too Old, No Replies

Dynamic Form Input using PHP - How?

         

m8fyu

10:42 am on Feb 11, 2011 (gmt 0)

10+ Year Member



I have a simple contact form (name, email, subject, message, submit) that I have for users to make enquiries.

Is there an easy way to populate the subject input field depending on the URL that the user has arrived at the form from? The title of each page is pretty descriptive so even if I passed this data to the form it would alleviate the user from having to type out a subject line.

Any advice is greatly appreciated as I'm pretty new to PHP and am finding it hard to find examples of how this can be achieved.

:)

omoutop

12:45 pm on Feb 11, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One idea is to use $_SERVER['HTTP_REFERER'].
This shows you from what url your user came.

So if i am in contact.htm and before that i was in sitemap.htm, $_SERVER['HTTP_REFERER'] will show: http://www.example.com/sitemap.htm.

Now, combine this with parse_url() or pathinfo() to get a cleaner url of he previous page.

But i am sure there are other ways as well

milocold

5:23 pm on Feb 11, 2011 (gmt 0)

10+ Year Member



Howdy,

basename('http://www.example.com/sitemap.htm');

Will give you just the page name, then you can use a switch statement to set your subject.

Hope that helps,

M. Cold

m8fyu

5:46 pm on Feb 11, 2011 (gmt 0)

10+ Year Member



Thanks guys. I'm not very familiar with either of these processes so I'll do a little extra research and let you know how I get on. Thanks again.