Hi
I have recently started to teach myself PHP so I'm sorry if this seems like a silly question but there
are a few things about submitting forms that has me a little confused.
When a form is submitted using say:
<form name="loginForm" action="login.php" method="post">
does the php to process the form have to be in the same document as the form, or can it be in a
separate document.
Thanks,
James
Submitting forms query
Moderator: General Moderators
Re: Submitting forms query
It can be in the same or a separate document (in fact you can have it post to a completely different server). In your example, login.php is the where the form information is passed to.
Re: Submitting forms query
Hi,
Thank you for your response. I thought it might be possible to put the php else where.
What has go me confused is the fact that I can not figure out how to send the form data
to the php document without leaving the current document to open the php document.
For example, I found a tutorial here: http://edrackham.com/php/php-login-script-tutorial/
There is a link to a form on that page. I looked at the source and it appears to be an
html form with no php. If I submit the form, it is processed and as far as I can see does not
open a php document. If I create a form and submit it, the browser leaves the form and
opens the php document to process the form. What am I doing wrong?
Thank again.
Thank you for your response. I thought it might be possible to put the php else where.
What has go me confused is the fact that I can not figure out how to send the form data
to the php document without leaving the current document to open the php document.
For example, I found a tutorial here: http://edrackham.com/php/php-login-script-tutorial/
There is a link to a form on that page. I looked at the source and it appears to be an
html form with no php. If I submit the form, it is processed and as far as I can see does not
open a php document. If I create a form and submit it, the browser leaves the form and
opens the php document to process the form. What am I doing wrong?
Thank again.
Re: Submitting forms query
He links to a php file when a user submits the form and directs them back to the same page:
/tutorials/user-membership-with-php-mysql/login.php
The above link is his form action.
Best wishes
/tutorials/user-membership-with-php-mysql/login.php
The above link is his form action.
Best wishes
Re: Submitting forms query
Hi,
Sorry for appearing a bit dense, but I am still a little confused.
When you say "He links to a php file and directs them back to the
same page", do you mean that there is a separate php file with
the same name (login.php) as the form? Or is it that the php is
contained in the login form but for some reason I can't see it
when I view page source?
Thanks,
James
Sorry for appearing a bit dense, but I am still a little confused.
When you say "He links to a php file and directs them back to the
same page", do you mean that there is a separate php file with
the same name (login.php) as the form? Or is it that the php is
contained in the login form but for some reason I can't see it
when I view page source?
Thanks,
James
Re: Submitting forms query
Firstly, PHP is server side coding so you wont be able to see the PHP when you view the source code of the page. You only get to see the execution results of that PHP code which is HTML.
In order to answer your question:
In this particular website you are refering to there is a login.php file with two forms for LOGIN and REGISTER. Now within that login.php page there will also be PHP code to execute the FORM POST details when submitted. I know this because the FORM ACTION ATTRIBUTE is directed back to the exact same page.
So there could be PHP code embeded directly within the login.php to handle the users request and execute them, or there could be an include() attribute in PHP within this login.php page that could call another .php page with all the PHP code in that. Either way you are still directed back to the same page you used to fill in the initial forms (LOGIN or REGISTER).
The FORM ACTION ATTRIBUTE directs the user back to the same login.php file which handles the user input. Either way you will not be able to see the syntax within the source code of the login.php page only the HTML and possible CSS values etc.
I hope this explains it all for you.
Best wishes
In order to answer your question:
In this particular website you are refering to there is a login.php file with two forms for LOGIN and REGISTER. Now within that login.php page there will also be PHP code to execute the FORM POST details when submitted. I know this because the FORM ACTION ATTRIBUTE is directed back to the exact same page.
So there could be PHP code embeded directly within the login.php to handle the users request and execute them, or there could be an include() attribute in PHP within this login.php page that could call another .php page with all the PHP code in that. Either way you are still directed back to the same page you used to fill in the initial forms (LOGIN or REGISTER).
The FORM ACTION ATTRIBUTE directs the user back to the same login.php file which handles the user input. Either way you will not be able to see the syntax within the source code of the login.php page only the HTML and possible CSS values etc.
I hope this explains it all for you.
Best wishes