/    Sign up×
Community /Pin to ProfileBookmark

How do you get the name of the HTML form that called the current PHP script?

I’m setting up a page with several forms that call the same script, just need the script to identify the form for processing.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@pyroSep 18.2005 — You could use $_SERVER['HTTP_REFERER']; but that isn't the most reliable way, as it is set by the user agent, so it cannot really be trusted.

The better way would be to include a something on the form itself that will identify it.
Copy linkTweet thisAlerts:
@strBeanauthorSep 18.2005 — Not included in the $_POST array then?
Copy linkTweet thisAlerts:
@NogDogSep 18.2005 — You can put it into the $_POST array by using a hidden field in the form, as Pyro sort of alluded to. Or, one time I simply gave the submit buttons different names on a couple different forms that called the same form-handler, then checked for which one called the script with something like:

[code=php]
if(isset($_POST['submit_1']))
{
# do this
}
elseif(isset($_POST['submit_2'))
{
# do this
}
else
{
# how did we get here?
}
[/code]
Copy linkTweet thisAlerts:
@strBeanauthorSep 18.2005 — That's what I wound up doing -- putting it in the form. No reason not to...

thx

Say, sorry for piggybacking an unrelated question:

I'm using mySQL "text" datatype for a free-form text area input. When the data comes back for display, there are no line feed characters. I see them in the source after it's displayed, but of course HTML doesn't find any >br> elements, so it's all one long paragraph.

Is there a "replace" string function that I can use to add the <br> elements? If so, how do I test for a linefeed carriage return character in PHP?

[b]Never mind - I found it[/b]

Thanks for everything.
Copy linkTweet thisAlerts:
@NogDogSep 19.2005 — [url=http://www.php.net/nl2br]nl2br()[/url]
Copy linkTweet thisAlerts:
@strBeanauthorSep 19.2005 — Better.

I used str_replace(chr(10),chr(10).'<br>',mystring)

Works, but the built-in looks nice, too.
Copy linkTweet thisAlerts:
@strBeanauthorSep 19.2005 — Hey --

Not too many people minding the store ov er on the javascript side.

[URL=http://www.webdeveloper.com/forum/showthread.php?t=79442]This [/URL] post about redirecting the browser if a cookie is set might interest your altruistic proclivities.
×

Success!

Help @strBean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...