Append a form on a php file (1 viewing) (1) Guests
Post Reply << Start < Prev 1 2 Next > End >>
Append a form on a php file
by jahflasher 6 Months, 1 Week ago
I am trying to improve my voting _script_ so that i dont have to subit votes from a form. It is possible to do this:

Code: :

  rate.php?value="<?php <form action="<?php echo $_SERVER['PHP_SELF']; ?>"   method="post"><input type="submit" name="value1" id="value1" value="1" /></form>?>          



Thanks for your response in advance.
Last Edit: 02/12/2008 04:15pm By jahflasher.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by cyberpunk 6 Months, 1 Week ago
before I start to think bout a how to do this let me first ask.. Why would you want to append a form via url element.. thats definitely out of the box but I'm not so sure its that safe.

You sir sound like your ready to venture into the world of ajax.. submiting just the voting information without reloading the entire web page? is that what your trying to attain?
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by jahflasher 6 Months, 1 Week ago
Yes that is what iam trying to do. Though thinking back now it does not make sense because i could easy pass it by simply doing this: rate.php?value=1. Ok this is it. If i knew a function that could take the url form the address bar example:
Code: :

 somesite.com/index.php?product_name=Juice&somevar=2&somothervar=23



and append another url element dynamaically at the end when i pass it using a simple url array (not bothering with the whole <form thingie>, so all the required data remains on the page even after another url element is passeed.
example: >

Code: :

 somesite.com/index.php?product_name=Juice&somevar=2&somothervar=23&ratevalue=1



. Thats it. I know that the function exist, but i done know how to find or use it.

I hope you understand what i am trying to say.
Last Edit: 02/13/2008 04:39pm By jahflasher.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by jahflasher 6 Months, 1 Week ago
i have come to realise that i can use $_SERVER['PHP_SELF'] and $_SERVER['QUERY_STRING'] to reconstruct the url string. But this is still limiting.Is there a fuction that can take all the url string in one and allow me to append another var to it?
Last Edit: 02/13/2008 07:11pm By jahflasher.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by cyberpunk 6 Months, 1 Week ago
why not rebuild it on the other side on your own?? as in.. if your limited by the server variables.. You'll have all elements available in the GET array. and you know the url you want it to be pushed into. Use a conditional statement or a series of them. to build your string. within each conditinoal block you concatenate the variable if its set and isn't empty.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by jahflasher 6 Months, 1 Week ago
Thats what i am doing now but after some time it gets cumbersome when you have to be checking if a var exist endless if else php statements. That is why i was hoping to find a function that does it automatically. But i guess i will have to go the old hard way .
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by cyberpunk 6 Months, 1 Week ago
I mean even if you did it ajax basically you'ld have to check if it exists.. What you could do is write a function.. I have my own little function list that i think i reuse on most if not all of my web development projects.

make a function that will go through the get array stack recursively and check if each array element is set and return which is and which isnt..

so basically you'ld just use that function each time you come upon a situation like this.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by jahflasher 6 Months, 1 Week ago
ok Then. Do you. Have an example of how to do this. I would really appreciate it.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by cyberpunk 6 Months, 1 Week ago
okay take a look at this particular function its purpose is to check the post stack recursively and add slashes to each array element before i insert them into the db.

Code: :

  function addslash_deep($poststack){     if(!empty($poststack)){         if(is_array($poststack)){             foreach($poststack as $x => $y){                 $poststack[$x] = addslashes($y);             }             return $poststack;         }         else{             $poststack addslashes($poststack);             return $poststack;         }     } }



now this was becuase i hated having to addslashes to each post stack element manually.

You could just past your get array to your function do whatever type of processing you wanna do with them and return the wholle array for manipulation after
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:Append a form on a php file
by jahflasher 6 Months ago
Unfortunatly because of my limted knowledge of php i am unable to modify that function. I have however found a function that does what i want. Only problem is it work on its own but when i call the function in a href _link_ i get errors.here is the function:
Code: :

 <?php function setUrlVariables() {  $arg = array();  $string "?";  $vars $_GET;  for ($i 0$i func_num_args(); $i++)    $arg[func_get_arg($i)] = func_get_arg(++$i);  foreach (array_keys($arg) as $key)    $vars[$key] = $arg[$key];  foreach (array_keys($vars) as $key)    if ($vars[$key] != ""$string.= $key "=" $vars[$key] . "&";  if (SID != "" && SID != "SID" && $_GET["PHPSESSID"] == "")    $string.= htmlspecialchars(SID) . "&";  return htmlspecialchars(substr($string0, -1)); } ?>


now i try to call it in a href:
Code: :

 <a href="getrate.php<?php echo setUrlVariables();?>">[1]</a>



i then get this fatal error message:
Fatal error: Cannot redeclare seturlvariables() (previously declared in /.........price/compare.php:407) in /.............price/compare.php on line 406

I dont know what i m doing wrong becuase according to its contributor notes i think i am on the right track as can be seen here:
If you're working with $_GET a lot and need to preserve already set variables in a _link_ for the next page, this function is pretty handy for simplifying the process of generating a new URL:
string setUrlVariables([string var, string value], [varN, valueN], ...)
<?php
function setUrlVariables() {
$arg = array();
$string = "?";
$vars = $_GET;
for ($i = 0; $i < func_num_args(); $i++)
$arg[func_get_arg($i)] = func_get_arg(++$i);
foreach (array_keys($arg) as $key)
$vars[$key] = $arg[$key];
foreach (array_keys($vars) as $key)
if ($vars[$key] != "") $string.= $key . "=" . $vars[$key] . "&";
if (SID != "" && SID != "SID" && $_GET["PHPSESSID"] == "")
$string.= htmlspecialchars(SID) . "&";
return htmlspecialchars(substr($string, 0, -1));
}
?>
You use it like this:
<a href="nextpage.php<?php echo setUrlVariables(); ?>">_link_</a>
In this case setUrlVariables() will simply add all the $_GET variables of the current page/URL and even takes care of the PHPSESSID if you use one (and didn't change the default variable name). The above HREF would complete to e.g.:
"nextpage.php?var=21&PHPSESSID=BI89J"
If you supply arguments, do it like this:
<?php echo setUrlVariables("user", "foobar"); ?>
This would complete the HREF to e.g.:
"nextpage.php?user=foobar&var=21&PHPSESSID=BI89J"
Unsetting variables works by supplying an empty value:
<?php echo setUrlVariables("var", ""); ?>
"nextpage.php?user=foobar&PHPSESSID=BI89J"
setUrlVariables() also makes sure it produces "pretty URLs", so it doesn't output any unnecessary garbage.
<?php
session_destroy();
echo setUrlVariables("user", "");
?>
"nextpage.php"
Last Edit: 02/15/2008 05:43pm By jahflasher.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Post Reply << Start < Prev 1 2 Next > End >>
 
     
Powered by FireBoardget the latest posts directly to your desktop