I have a simple form (text fields and 4 checkboxes) redirecting to a new page and I followed this old thread on how to "echo" the results...
https://www.coffeecup.com/forums/web-fo … on/?page=1
and everything is working fine except for the checkboxes. It just ouputs as "Array".
The line " echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>' " does show if a checkbox(s) has been selected (or not) for the checkbox array (outside quotes are mine - not in the actual php)
but in the Session post (which is what I want to show) it just says Array, because that is what a checkbox field is, an Array (I guess - not an expert here).
Radio buttons work fine using this approach, as do dropdowns, but not checkboxes.
I've read that it possibly has to do with the checkbox Array being inside the Session post array (array inside of an array), but I can't find a solution on how to define it correctly to look for the checkbox[] options, rather than just returning the checkbox name as an Array?
Clear as mud right?
areyou is the name of the checkbox array. Output is always " Are you: Array "
<?php
$post = $_SESSION['post']; // This is getting the post array
$interested = $post['interested']; // This is getting which house
$firstname = $post['firstname']; // This is getting firstname
$lastname = $post['lastname']; // This is getting lastname
$streetaddress = $post['streetaddress']; // This is getting address
$city = $post['city']; // This is getting city
$state = $post['state']; // This is getting state
$postalcode = $post['postalcode']; // This is getting postal code
$emailaddress = $post['emailaddress']; // This is getting email
$areyou = $post['areyou']; // This is the checkbox array which has four options
// Add more as needed for each input on your form. Adjust to your input name.
if(isset($_SESSION['post'])) {echo'You made it to my page.<br><br> Here is what you chose on my form.<br><br>
'.$interested.'<br><br>
First Name: '.$firstname.'<br><br>
Last Name: '.$lastname.'<br><br>
Street Address: '.$streetaddress.'<br><br>
City: '.$city.'<br><br>
State: '.$state.'<br><br>
Postal Code: '.$postalcode.'<br><br>
Email: '.$emailaddress.'<br><br>
Are you: '.$areyou.'<br><br>
Refresh your browser to see the Session unset.<br><br>
Here\'s the session array. The one that holds the form variables is named post.';
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
}
else{echo 'You need to make choices <a href="dont-unset-variables/index.html">on my form</a>.';
}
unset($_SESSION['post']); // This unsets the $_SESSION['post'] array
// Here's how to unset one variable.
//$key=array_search($post['number'],$_SESSION['post']);
// if($key!==false) unset($_SESSION['post'][$key]);
?>
Any advice would be greatly appreciated!
Form results using redirect URL for...
Hi William,
Here's one way to handle it.
Here's one way to handle it.
if(!empty($post['areyou'])) {
foreach($post['areyou'] as $value){
echo "You are : ".$value."<br/>";
}
}
foreach($post['areyou'] as $value){
echo "You are : ".$value."<br/>";
}
}
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.
This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
It's easy to overlook something you're not looking for.
This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
Hi Eric,
Thank you, that will work just fine. I really have to learn some php
Thank you, that will work just fine. I really have to learn some php
Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.