itsjareds Posted June 30, 2008 Share Posted June 30, 2008 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; Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 i think i see what you are doing...try this: fwrite($handle,"\$statarray['{$name}'] = \"".$status."\"\r\n"); Quote Link to comment Share on other sites More sharing options...
itsjareds Posted June 30, 2008 Author Share Posted June 30, 2008 That looks right, but it's not writing into array.php for whatever reason. I'm not even sure if the script works even TO that point. I really am clueless ??? It seems like it should work. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 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"); ?> Quote Link to comment Share on other sites More sharing options...
itsjareds Posted June 30, 2008 Author Share Posted June 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 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"); ?> Quote Link to comment Share on other sites More sharing options...
itsjareds Posted June 30, 2008 Author Share Posted June 30, 2008 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> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 oh...you can't nest forms Quote Link to comment Share on other sites More sharing options...
itsjareds Posted July 1, 2008 Author Share Posted July 1, 2008 What could I do to keep that form in the other one? I need it in that spot. I almost want to just use an iframe and make it directed to my site.. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 1, 2008 Share Posted July 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
itsjareds Posted July 1, 2008 Author Share Posted July 1, 2008 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 That sounds good, but how do I give it a different form action? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 1, 2008 Share Posted July 1, 2008 good point...guess you can't (unless you alter that with the javascript too) ...can you detail further what you are trying to accomplish...maybe there is another solution Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 1, 2008 Share Posted July 1, 2008 You can have one action script and decide what to do based on the value of $_POST['submit'] Ken Quote Link to comment Share on other sites More sharing options...
itsjareds Posted July 1, 2008 Author Share Posted July 1, 2008 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. :'( Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 1, 2008 Share Posted July 1, 2008 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" Quote Link to comment Share on other sites More sharing options...
itsjareds Posted July 1, 2008 Author Share Posted July 1, 2008 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 I'll try it. If you absolutely want to know more, look here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.