Jump to content

Help - Converting values

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
ghost2012

ghost2012

    Newbie

  • Members
  • PipPip
  • 16 posts
Need help converting the code where it will accept and process
inputs from checkbox to text

This is the html code:
<form action="process.php" method="post">
<p>What is your name?</p>
<p><input type="text" name="customer_name"></p>

<p>What orders do you want?</p>
<p>
<input type="checkbox" name="hworder[]" value="order01"> Order01
<br />
<input type="checkbox" name="hworder[]" value="order02"> Order02
<br />
<input type="checkbox" name="hworder[]" value="order03"> Order03 
<br />
<input type="checkbox" name="hworder[]" value="order04"> Order04</p>
<input type="submit"> 
</form>

This is the process.php code:
<?php

$hworder = $_POST["hworder"];
$customer_name = strval($_POST["customer_name"]);

if (is_array($hworder)) {
    foreach ($hworder as $key => $value) {
        print "$customer_name ordered $value .<br>";
    }
}

?>
It processes the checkboxes with no problem when I convert to text and try to get only values that I've submitted. Instead of receiving all.

Ok thats where I'm at.
Help please.

Edited by Orjan, 28 October 2009 - 01:54 AM.
Please, use code, html and/or php tags for code...


#2
ghost2012

ghost2012

    Newbie

  • Members
  • PipPip
  • 16 posts
I'm just now learning how to get information from one page to another. So I'm using a script that I found and modifying it to where instead of using checkboxes I can receive info from text input and receive only that which was entered and submitted

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
I don't understand your problem really.
checkboxes only return their values if they are checked. non filled checkboxes is never returned.

what do you want help with? As I can see, that code should work?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#4
Jacki

Jacki

    Learning Programmer

  • Members
  • PipPipPip
  • 80 posts
checkbox return true or false.
you can do:
foreach ($hworder as $hw => $order) { 
if($order)
print "$customer_name ordered order$hw .<br>";
}

Posted Image

Posted Image

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
No Jacki, Checkboxes returns it's value if checked or nothing if not checked.

but if you evaluate a nonexisting variable, it returns the bool answer false, and if you evaluate the existing variable, and it's value is not 0, it will return bool true.

<form action="index.php" method="GET">
<input type="checkbox" name="test1" value="on"/>
<input type="checkbox" name="test2" value="donkey"/>
<input type="checkbox" name="test3" value="0"/>
<input type="submit" name="submit" value="Send"/>
</form>

if you check all three boxes, the GET string will be:
index.php?test1=on&test2=donkey&test3=0&submit=Send

but if you don't check any boxes, the GET string will be:
index.php?submit=Send

and if only the mid one is checked, the GET string will be:
index.php?test2=donkey&submit=Send

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#6
ghost2012

ghost2012

    Newbie

  • Members
  • PipPip
  • 16 posts
thats just it i'm not wanting to use checkboxes i want to know how to use text boxes where i can recieve data input from a form and data that is all readly set. i just don't know how to format the php to recieve it

#7
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
you do as with the checkboxes? the text content of the textboxes will be inside the $_POST (or $_GET / $_REQUEST) variable with the name of the input as an array key
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall