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
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");

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

yeah...it should work fine...put this code in there and tell me what the output is:

 

<?php
  print_r($_POST);
  $alert = "array.php";
  if(!is_file($alert)) die("File doesn't exist");
  if(!is_writable($alert)) die("File is not writable");
?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.  :'(

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.