I understand that it validate form data on the same page, but what if i want my form data to be handled by example.php can I use PHP_SELF and example.php together on some condition?
Asked
Active
Viewed 89 times
-2
-
I would recommend avoiding `$_SERVER['PHP_SELF']`. it is very easy to inject malicious data by simply appending `/ – reinierkors Jun 07 '17 at 12:05
-
PHP_SELF more information click here https://www.w3schools.com/php/php_form_validation.asp – Khetesh kumawat Jun 07 '17 at 12:07
-
either you can use php_self or the page name directly. – Niladri Banerjee - Uttarpara Jun 07 '17 at 12:08
-
Do you mean to use either `PHP_SELF` or `example.php` based on some condition? – k32y Jun 07 '17 at 12:12
1 Answers
0
If you want to submit your form to the same page, i.e. PHP_SELF
when a condition is met and submit it to example.php
when a different condition is met, then try this:
<form method="POST"
action="<?php echo $some_condition == "some_value" ? $_SERVER['PHP_SELF'] : 'example.php' ?>">
...
Your form content here
...
</form>
You will replace $some_condition == "some_value"
with whatever condition you want to check.

k32y
- 407
- 6
- 11
-
thanks alos @k32y . again please can you help me with this, am getting this error Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\Documents and Settings\Eddyboy\My Documents\Downloads\xampp-win32-1.7.2\xampp\htdocs\registern.php:1) in D:\Documents and Settings\Eddyboy\My Documents\Downloads\xampp-win32-1.7.2\xampp\htdocs\registern.php on line 3 – Iyayi Eddy Jun 08 '17 at 05:48
-
`session_start()` has to be called before you print any output to the screen. if possible let it be the first statement in your script. You are getting that error probably because your script threw an error somewhere and the error message is printed before your `session_start()` statement is executed. – k32y Jun 08 '17 at 08:55
-
@IyayiEddy were you able to solve the problem? If so accept this answer if it helped you or provide the solution that worked for you to help others that might face the same issue. – k32y Jun 13 '17 at 07:55