niche Posted June 23, 2010 Share Posted June 23, 2010 This script: <form method="post" action="mailto:youremail@email.com">Shade:<input type="checkbox" name="shade" > <br />Color:<input type="checkbox" name="color" ><br /><input type="submit" value="Submit"></form> It can produce this result: shade=on&color=on.If I sent the result to a php script instead, how can that script produce an array (ie is the output identified in way that array() can be used). If not how else can the output be used to produce an array?Thanks Link to comment Share on other sites More sharing options...
wirehopper Posted June 23, 2010 Share Posted June 23, 2010 http://www.php.net/manual/en/function.parse-str.php Link to comment Share on other sites More sharing options...
niche Posted June 23, 2010 Author Share Posted June 23, 2010 Thanks. In an example like mine, how do I identify the form's output so I can use parse_str()? Link to comment Share on other sites More sharing options...
wirehopper Posted June 23, 2010 Share Posted June 23, 2010 The code you posted uses post, the string you posted would be a querystring or the submission of the form inputs through get.Both arrive in PHP as arrays. $_POST and $_GET, and are present in $_REQUEST - which also includes some other variables. The inputs are represented in the arrays as indicies, with the value of the inputs. For the code above, the input "shade" would look like: $_POST['shade'] in PHP.Checkboxes are different than other inputs, because if they aren't checked, the value isn't sent from the client. That's why it's good to use code like this:$bShade=(isset($_POST['shade']) && ($_POST['shade']=='on'));This checks to be sure the shade input was sent from the client and the value sent was on. If the value wasn't sent, or it's not on, $bShade will be false. If you don't use isset, an error may be reported when the code executes.You can view them with var_dump - for example var_dump($_POST)If you would like to use parse_str, you should be able to use parse_str($_SERVER['QUERY_STRING']) Link to comment Share on other sites More sharing options...
niche Posted June 23, 2010 Author Share Posted June 23, 2010 wirehopper, great threads. Your last reply helped a lot.Thanks,Niche Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.