Welcome Guest, Not a member yet? Register   Sign In
$_SERVER['PHP_SELF'];???
#1

[eluser]husni[/eluser]
hey guys..can i use
Code:
$SERVER_['PHP_SELF'];
in my application..
i want to execute something in same page..
where i should put the code? view or controller file??
and how to do it..

i need to display all the list of report and before that i must choose the options which category i want to search..
#2

[eluser]danmontgomery[/eluser]
It's $_SERVER, not $SERVER_

No, you shouldn't use it. You should use the CI function current_url().
#3

[eluser]husni[/eluser]
[quote author="noctrum" date="1267474938"]It's $_SERVER, not $SERVER_

No, you shouldn't use it. You should use the CI function current_url().[/quote]

i have a form that have conditios about what i am going to search about..
and at the bottom of the form..after i click search button,the result will appear at the bottom of the form..means execute in the same page..

how can i do that??
#4

[eluser]maria clara[/eluser]
PHP Forms in native PHP


Using forms in a web based application is very common. Most forms are used to gather information like in a signup form, survey / polling, guestbook, etc.

A form can have the method set as post or get. When using a form with method="post" you can use $_POST to access the form values. And when the form is using method="get" you can use $_GET to access the values. The $_REQUEST superglobal can be used to to access form values with method="post" and method="get" but it is recommended to use $_POST or $_GET instead so you will know from what method did the values come from.

Here is an example of HTML form :

Code:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name : <input name="username" type="text"><br>
Password : <input name="password" type="password"><br>
<input name="send" type="submit" value="Send!">
</form>
The form above use $_SERVER['PHP_SELF'] as the action value. It is not required for the form to perform correctly but it's considered good programming practice to use it.

Below is the PHP code used to access form values :


Code:
<?php
if(isset($_POST['send']))
{
   echo "Accessing username using POST : " .         $_POST['username'] . "<br>";
   echo "Accessing username using REQUEST : " .         $_REQUEST['username'] . "<br>";

   $password = $_POST['password'];
   echo "Password is $password";
}
?&gt;
The if statement is used to check if the send variable is set. If it is set then the form must have been submitted. The script then print the value of username using $_POST and $_REQUEST


Using Array As Form Values

Take a look at the code example below. The form have five input with the same name, language[]. Using the same input name is common for checkboxes or radio buttons.


Code:
&lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;"&gt;
Select the programming languages you can use<br>
&lt;input name="language[]" type="checkbox" value="C++"&gt;
C++<br>
&lt;input name="language[]" type="checkbox" value="Java"&gt;
Java<br>
&lt;input name="language[]" type="checkbox" value="PHP"&gt;
PHP<br>
&lt;input name="language[]" type="checkbox" value="ASP"&gt;
ASP<br>
&lt;input name="language[]" type="checkbox" value="Delphi"&gt;
Delphi<br>
&lt;input name="send" type="submit" id="send" value="Send!"&gt;
&lt;/form&gt;

The PHP code below print the value of language after the form is submitted. Go ahead and try the example. Try checking and unchecking the options to see the effect.

Example : form-array.php
Source code : form-array.phps

Code:
&lt;?php
if(isset($_POST['language']))
{
   $language = $_POST['language'];
   $n        = count($language);
   $i        = 0;

   echo "The languages you selected are \r\n" .
        "<ol>";
   while ($i < $n)
   {
      echo "<li>{$language[$i]}</li> \r\n";
      $i++;
   }
   echo "</ol>";
}
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB