SitePoint Sponsor |
|
User Tag List
Results 1 to 18 of 18
Thread: Calling local php with submit
-
Nov 26, 2008, 13:17 #1
- Join Date
- Nov 2005
- Location
- Southern Nevada, USA
- Posts
- 150
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Calling local php with submit
I have seen where you can open an external php file when clicking on a Submit button in a form, but how can I activate a local php file only when the Submit button is clicked?
Lawrence
-
Nov 26, 2008, 13:25 #2
What do you mean by 'local php file'? And by 'activate'?
Guido - Community Team Leader
The Votes Are In: The Winners of the 2013 Community Awards are...
Blog - Free Flash Slideshow Widget
-
Nov 26, 2008, 13:30 #3
- Join Date
- Nov 2005
- Location
- Southern Nevada, USA
- Posts
- 150
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have a form and beneath the form I have a php file that loads information into a data base. I don't want the php file to run until the form is complete filled in, and the Submit button is clicked.
By local, I meant a php file on the same page as the form, not an external php file.
Lawrence
-
Nov 26, 2008, 13:35 #4
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
In that case, check for the existence of the $_POST array. Put the processing above the form, not below it:
PHP Code:<?php
$errors = array();
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
//form validation and handling here
if(count($errors) < 1) header('location: http://www.yoursite.com/success.php');
}
//show the form. You can use the $errors array to inform the user of any errors.Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Nov 26, 2008, 13:51 #5
- Join Date
- Nov 2005
- Location
- Southern Nevada, USA
- Posts
- 150
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have other forms on this page with their individual submit buttons. Will this still work?
It appears this is calling an external php file, I want to run a php file that is located in the same file as the forms. The reason for this is I want to use some other variables located on the same page but not as a result of a form.
Lawrence
-
Nov 26, 2008, 14:03 #6
- Join Date
- Oct 2006
- Location
- France, deep rural.
- Posts
- 6,869
- Mentioned
- 17 Post(s)
- Tagged
- 1 Thread(s)
If you want to post back to the same page (called a postback) make sure your form action looks like this:
File: index.php
PHP Code:<form method=POST action=index.php name=myform>
File: something.php
PHP Code:<form method=POST action="" name=myform>
-
Nov 26, 2008, 14:44 #7
If each submit button has to trigger a different php script, then you'll have to give each a unique name or value, and check for it's existance/value.
It appears this is calling an external php file, I want to run a php file that is located in the same file as the forms.
The reason for this is I want to use some other variables located on the same page but not as a result of a form.
So, any values set in the script the first time, but not saved in some way (hidden fields in the form, session values or whatever), will NOT be there anymore when the form is sent.Guido - Community Team Leader
The Votes Are In: The Winners of the 2013 Community Awards are...
Blog - Free Flash Slideshow Widget
-
Nov 26, 2008, 15:13 #8
-
Nov 27, 2008, 03:56 #9
- Join Date
- Oct 2006
- Location
- France, deep rural.
- Posts
- 6,869
- Mentioned
- 17 Post(s)
- Tagged
- 1 Thread(s)
Use of PHP_SELF was considered harmful. Has that changed?
Leaving it blank seems to work for me though.
-
Nov 27, 2008, 05:35 #10
-
Nov 27, 2008, 07:16 #11
- Join Date
- Oct 2006
- Location
- France, deep rural.
- Posts
- 6,869
- Mentioned
- 17 Post(s)
- Tagged
- 1 Thread(s)
It goes back a few years but reading about PHP_SELF attacks stopped me using it.
-
Nov 27, 2008, 07:43 #12
-
Nov 28, 2008, 00:15 #13
- Join Date
- Nov 2005
- Location
- Southern Nevada, USA
- Posts
- 150
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you can't use "PHP_SELF" for the action, and you can't leave it blank, and it is recommended that you show an action, what is the approved method of submitting the form data to php code listed on the same page as the form?
A search for "form submit action" on Google provides very little information on this.
Lawrence
-
Nov 28, 2008, 02:53 #14
-
Nov 28, 2008, 03:13 #15
- Join Date
- Oct 2006
- Location
- France, deep rural.
- Posts
- 6,869
- Mentioned
- 17 Post(s)
- Tagged
- 1 Thread(s)
- Have the value hard coded in there
Plus, in these days of Ajaxified interfaces the form action is becoming less relevant.
BTW, I am generalising about Admin interfaces, where I tend spend 90% of my time.
On public webs, with concrete urls almost sacrosanct, then I am pretty sure I hard code the Action without question.
Perhaps that clarification makes the suggestion to leave it blank makes it seem less radical.
-
Nov 28, 2008, 03:25 #16
- Join Date
- Oct 2008
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i all always submit the PHP files online to test, use the loacal php file it seems no useful
-
Nov 28, 2008, 04:31 #17
- Join Date
- Oct 2008
- Posts
- 295
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have used usually $_SERVER['SCRIPT_NAME'] instead of PHP_SELF.
-
Dec 1, 2008, 23:30 #18
- Join Date
- Nov 2005
- Location
- Southern Nevada, USA
- Posts
- 150
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks