Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello There, I am very new here in this forum. I was wondering about something and thought asking you guys. I am working with a project where I have too much files. all with php extensions. I have various HTML forms in every pages of my site. and every time I am creating a new php file and linking it up to action attribute of the html form tag, to take the form input tag values. Now I was wondering that If I could just make one file which recognize all the forms in my project and whenever any form is submitted to the server so the file will only take the values of that specific form. I will be really glad If I get a help.
Posted

It sounds like you want one php to handle the input from many different forms. That is easy to do, but then you need it to know which form provided the data. There are two simple ways to do this:
1. Add a hidden input field to each form with the same name but different values on each form, so you can always refer to that input field to see which form it was.
HTML
<form action="mycommonaction.php" method="get">
...
<input type="hidden" name="formid" value="form1"> 
...
</input></form>

PHP
$originalform = $_GET['formid'];
if ($originalform == 'form1')
    ...

2. Look at the Referer header in the request to see which form was used.
PHP
$originalURL = $_SERVER['HTTP_REFERER'];
// parse $originalURL to extract form name part...


Either of these will work, but the hidden input field is probably a bit easier to manage.

Cheers,
Peter
If this answers your question, mark it accepted. Vote anyway.
 
Share this answer
 
Hello Peter,

Thank you so much. first when I read your answer it was not really clear. I was a bit confused. But the clue that you gave me about the hidden input tag and its name and value attributes was really making it work in my mind. I tried a bit and it was solved. I would really like to thank you for that. Thanks :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900