Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    Kelowna, British Columbia
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    create variables from checkboxes and radio buttons for sending simple email output

    Hello, I've been reading and reading trying to figure out what my best bet is for making checkbox and radio button values into variables and just simply pass them to a php script to email those only with values. The more i read the more I get confused as this seems to be a complex issue when getting into arrays and such.

    My Php is very, very beginner level. However, I'm thinking for what I need to do it could be quite simple. I would prefer to stay away from arrays for now until I have time to practice my code and get more advanced with it.

    My form is for an on-line job application. The radio buttons and one text field (for other comment) are a list of how the user found out about the position.

    The list of checkboxes are for the level of education the user has (therefore they can check more than one)

    Then I take these values from the form along with along with some other variables (but these are straight forward text values and file uploads) and pass them to my php script to email them to the recipient.

    Where I stumble is:

    1) I have a list of 8 radio buttons for choices and 1 text field as an "other" option if their answer isn't a radio button. So on my php script I don't want to send all variable values in email because all but one would have no value. How would I instruct the script to know which one to send?

    2) I have a list of checkboxes where any, all or none may be checked. Is there a rookie (very easy) way of sending the checked ones only in the email without getting into arrays? or is there a "beginners" level array function I can understand?

    I have named each radiob and ckbx uniquely if this helps

    Thank you for any help/suggestions/examples/etc...
    Last edited by percept; 01-16-2004 at 08:09 AM.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    <input type="radio" value="yes" name="radiob">
    <input type="radio" value="no" name="radiob">
    <input type="radio" value="maybe" name="radiob">

    <input type="checkbox" value="blue" name="chkbx[]">
    <input type="checkbox" value="green" name="chkbx[]">
    <input type="checkbox" value="yellow" name="chkbx[]">

    note the [] in chkbx[]

    ... in the receiving script ..

    PHP Code:
    <?php
    echo 'Selected radiob value = ' $_POST['radiob'] .'<br />';
    echo 
    'Selected checkbox value(s) = ' implode' , ' $_POST['chkbx'] );
    ?>
    implode() qives a quick and dirty way of viewing the array contents as a string (here seperated by a comma)


    .. alternately you could loop through the 'chkbx' array like so

    PHP Code:
    <?php
    foreach( $_POST['chkbx'] as $checkbox ){
        echo 
    $checkbox .'<br />';
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Dec 2003
    Location
    Kelowna, British Columbia
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for simplifiying this fIrepages, it was the [] that had me... I didn't think my case was too complicated but the tutorials and research I did made it very difficult to figure out.
    cheers

  • #4
    New Coder
    Join Date
    Dec 2003
    Location
    Kelowna, British Columbia
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm a little stuck on the conditional statement if the user uses the "other" input text box. In other words, if the user's answer is not one of the radio buttons, they can add input into a text field as an option. So where I'm stuck is how to set this conditional statement. Here's what I have and I'm not sure what to put in as a value where the word "checked" is.

    PHP Code:
    if (' . $_POST['radiob'] . ' == "checked" {
            
    $how_find ' . $_POST['radiob'] . ';
            
            } else {
                
    $how_find ' . $_POST['hf_other'] . ';
                } 
    thanks for any help in this matter...

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    you need to check if the $_POST['radiob'] form value is set/empty

    PHP Code:
    <?
    if ( !empty( $_POST['radiob'] ) ) {
        
    $how_find =  $_POST['radiob'] ;
    } else {
        
    $how_find $_POST['hf_other'] ;
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New Coder
    Join Date
    Dec 2003
    Location
    Kelowna, British Columbia
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    splendid! thanks mate!!
    percept


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •