Jump to content

Posting into an array


itsjareds

Recommended Posts

Hi, i'm writing a script to write information into an array from a form.

 

entryform.html

<form action="http://www.example.com/status/form.php" method="post">
<input type='hidden' value='itsjareds' name='name'>
<input type="text" name="status">   
<input type="submit" value="Set">

 

form.php

<?php

$name = $_POST["name"];
$status = $_POST["status"];

$alert = "array.php";

$handle = @fopen($alert,'a');
if($handle)
{
  fwrite($handle,"$statarray[".$name."] = '.$status.'\r\n");
  fclose($handle);
}

?>

 

array.php

$statarray = Array();

 

I need the final output of the script to write what was in the text field and hidden field on entryform.html to be written to array.php as:

$statarray = Array();
$statarray[$name] = $status;

Link to comment
https://forums.phpfreaks.com/topic/112518-posting-into-an-array/
Share on other sites

well, remove the @ and see if it give you any errors. and add an else to let you know if the file isn't opened...

 

<?php

$name = $_POST["name"];
$status = $_POST["status"];

$alert = "array.php";

$handle = fopen($alert,'a');
if($handle)
{
  fwrite($handle,"\$statarray['{$name}'] = \"".$status."\"\r\n");
  fclose($handle);
}else
  die("Failed to open file");

?>

I forgot to mention, the form is on a separate domain added through a Greasemonkey script. I want to add this form to a site I use, but I want it to use a form that is on my site.

 

I tested the same php form script from my site and it worked fine.

 

Why won't it work on the separate site?

 

I asked if forms could work cross-domain on this same forum, and i got a reply saying yes.

It gave me this when I tested it on my site:

Array ( [name] => KnifeySpooney [status] => testing )

 

I think the real form is not sending correctly from the site it is on.

 

Here what the coding should be after I add my form through javascript:

// Form generated by site
<form action="randomform.php" method="post">
<input type="radio" value="1" name="blah">    <input type="radio" value="0" name="blah">
<input type="radio" value="1" name="blah">    <input type="radio" value="0" name="blah">
<input type="radio" value="1" name="blah">    <input type="radio" value="0" name="blah">
<input type="radio" value="1" name="blah">    <input type="radio" value="0" name="blah">

// My form
<form action="http://www.example.com/status/form.php" method="post">
<input type="hidden" value="itsjareds" name="name">
<input type="text" name="status">
<input type="submit" value="Set">
</form>

// Rest of the first form
<input type="radio" value="1" name="blah">    <input type="radio" value="0" name="blah">
<input type="radio" value="1" name="blah">    <input type="radio" value="0" name="blah">
<input type="submit" value="Submit">
</form>

you can add just the elements, and an extra submit button...it will post all the data, but but you can just ignore everything else

 

or you can put the form outside the other form, and use CSS to position it

 

or your iframe should work too...but i hate iframes :)

You can have one action script and decide what to do based on the value of $_POST['submit']

 

Ken

 

This is all added through a greasemonkey script, which means that the site the form is on is not mine. I am only adding/editing elements through javascript. I can't edit their php script, so i can't do that.  :'(

ok...i would go with the absolutely positioned DIV...so have the JS add the form to the end of the page, and then position it absolutely using CSS

 

if you can't get that to work, i guess go with the iframe

 

i'm also interested in hearing as to why you "need it in that spot"

i'm also interested in hearing as to why you "need it in that spot"

 

The point of my script is to add a setting for people to change their status from "Online" to whatever. Theres a page with all the settings in one spot, and I need to have it placed there to make it look more natural and like it is supposed to be there.

 

Thanks for the help ;D I'll try it.

 

If you absolutely want to know more, look here.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.