Jump to content
Larry Ullman's Book Forums

Recommended Posts

I was wandering if someone could help with this. I have created 2 combo boxes and the values from combo1 populate combo2. Combo box 2 is multi select.

 

I then created the form processor to send the user a copy of what they have selected from the form.

 

The problem I have is when the email is received by the user, where I have added "Main Industry" it shows a number. How can I get the email to show the main value i.e. "Agriculture" "Hospitality" instead of the values "1" "2"

 

The second thing I cannot seem to work out is where I have "Job Skills" on the email which is basically values from combo2. It will only send the user 1 item, so if the user holds down the CTRL key and selects 3 items it's only the last item that gets sent.

 

I have attached the scripts as below. Or is java not the best way to do this?.

This is the form structure and the java script:

 

<select name="job_cat" size="1" id="Combobox1" onchange="fillSecondCombo();return false;" style="position:absolute;left:156px;top:451px;width:167px;height:22px;z-index:15;" title="Job Category:">

 

<option selected value="0">Please select an option</option>

 

<option value="1">Agriculture</option>

 

<option value="2">Catering and Hotel Work</option>

</select>

 

<select name="job_skills" size="1" id="Combobox2" style="position:absolute;left:127px;top:486px;width:202px;height:20px;z-index:16;" title="Job Skills:">

 

</select>

 

 

<script type="text/javascript">

 

function fillSecondCombo()

 

{

 

var combo1 = document.getElementById('Combobox1');

 

var combo2 = document.getElementById('Combobox2');

 

var selected = combo1.options[combo1.options.selectedIndex].value;

 

if (selected == 1)

 

{

 

combo2.options.length = 3;

 

combo2.options[0] = new Option("Agricultural Engineer", "Agricultural Engineer");

 

combo2.options[1] = new Option("Animal Care", "Animal Care");

 

combo2.options[2] = new Option("Dairy Worker", "Dairy Worker");

 

combo2.options[3] = new Option("Farm Worker", "Farm Worker");

 

combo2.options[4] = new Option("Harvesting Equipment Driver", "Harvesting Equipment Driver");

 

combo2.options[5] = new Option("Tractor Driver", "Tractor Driver");

 

combo2.options[6] = new Option("Zoo and Safari Park Worker", "Zoo and Safari Park Worker");

 

combo2.options[7] = new Option("Other (As Per CV)", "Other (As Per CV)");

 

}

 

else

 

if (selected == 2)

 

{

 

combo2.options.length = 3;

 

combo2.options[0] = new Option("Baker", "Baker");

 

combo2.options[1] = new Option("Bar Worker", "Bar Worker");

 

combo2.options[2] = new Option("Barista", "Barista");

 

combo2.options[3] = new Option("Butcher", "Butcher");

 

combo2.options[4] = new Option("Chef / Cook", "Chef / Cook");

 

combo2.options[5] = new Option("Catering Manager", "Catering Manager");

 

combo2.options[6] = new Option("Housekeeping", "Housekeeping");

 

combo2.options[7] = new Option("Hotel Management", "Hotel Management");

 

combo2.options[8] = new Option("Hotel Front of House", "Hotel Front of House");

 

combo2.options[9] = new Option("Hotel Portering", "Hotel Portering");

 

combo2.options[10] = new Option("Licensed Premises Manager", "Licensed Premises Manager");

 

combo2.options[11] = new Option("Restaurant Manager", "Restaurant Manager");

 

combo2.options[12] = new Option("Waiting at Tables", "Waiting at Tables");

 

combo2.options[13] = new Option("Other (As Per CV)", "Other (As Per CV)");

 

}

 

 

 

}

 

</script>

 

This is the email script:

 

<?php

if($_SERVER['REQUEST_METHOD'] == 'POST')

{

$mailto = 'paul@myemail.co.uk';

$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;

$subject = 'Website form';

$message = 'Values submitted from web site form:';

$success_url = './../Mail_Folder/success.php';

$error_url = './../Mail_Folder/fail.html';

$header = 'From: '.$mailfrom.$eol;

$header .= 'Reply-To: '.$mailfrom.$eol;

$header .= 'MIME-Version: 1.0'.$eol;

$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;

$header .= 'X-Mailer: PHP v'.phpversion().$eol;

{

$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;

}

else

{

$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;

}

}

}

$body = 'This is a multi-part message in MIME format.'.$eol.$eol;

$body .= '--'.$boundary.$eol;

$body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;

$body .= 'Content-Transfer-Encoding: 8bit'.$eol;

$body .= $eol.stripslashes($message).$eol;

if (!empty($_FILES))

{

foreach ($_FILES as $key => $value)

if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)

{

$body .= '--'.$boundary.$eol;

$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;

$body .= 'Content-Transfer-Encoding: base64'.$eol;

$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;

$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;

}

}

}

$body .= '--'.$boundary.'--'.$eol;

mail($mailto, $subject, $body, $header);

header('Location: '.$success_url);

exit;

}

?>

Link to comment
Share on other sites

Hope you don't mind if I add my two cents again.

First things first, please increase the size of your code and/or place it within code tags. You can do this easily by editing your original post.

Please do it.

 

To answer your questions, when a form is posted, the values set for the "value" attributes in the opening option tags are what are stored in the $_POST array. As such, if you have 0, 1, 2, etc. set for the "value" attributes, then that's what you'll get in the $_POST array.

You could set the actual strings displayed on the screen for the "value" attributes as well, but I think a better solution is to refer back to the array you used to generate the option elements in the first place to get the value you want.

 

As an example:

 

<?php

 // Assume that there is other appropriate HTML surrounding this block of PHP.

 $breakfast = array('Eggs', 'Bacon', 'Orange juice');

 if (isset($_POST['breakfast'])) {

   // We can use the $breakfast array above to get the actual item selected. For example:

   echo $_POST['breakfast']; // This echoes 0, 1 or 2 (i.e., the "value" attribute value).

   echo $breakfast[$_POST['breakfast']]; // This echoes 'Eggs', 'Bacon' or 'Orange juice' (i.e., the text within the option tags).

 }

 echo '<form action="this_script.php" method="post">';

 echo '<select id="breakfast" name="breakfast">';

 foreach ($breakfast as $key => $val) {

   // In this loop, $key is 0, 1 and 2, and $val is 'Eggs', 'Bacon' and 'Orange juice'.

   echo '<option value="' . $key . '">' . $val . '</option>';

 }

 echo '</select>';

 echo '<input type="submit" value="Submit">';

 echo '</form>';

?>

 

As the above demonstrates, if you use an array to populate the option elements of a select element, you can simply use that same array to get the actual values at a later time. Just make sure that you place the $breakfast array (or whichever array) above the if statement checking for POST data.

 

For your select combo box, which to my understanding and memory from last time is actually just a bunch of check boxes, in order to return multiple values to the POST array, you have to do something like the following:

 

<!-- Bad -->

<input type="checkbox" id="someID" name="someName"> Item 1

<input type="checkbox" id="someID2" name="someName"> Item 2

<input type="checkbox" id="someID3" name="someName"> Item 3

<!-- Doing the above will only get you the last value. -->

<!-- Good -->

<input type="checkbox" id="someID" name="someName[]"> Item 1

<input type="checkbox" id="someID2" name="someName[]"> Item 2

<input type="checkbox" id="someID3" name="someName[]"> Item 3

<!-- Notice the values set for the name attributes. By adding square brackets, all the values will be preserved in an array within the $_POST array. -->

 

Basically, you need to use a consistent value for all the name attributes and add [] onto the end to store those values into an array, which can hold multiple values.

 

As a last point, you said "Or is java not the best way to do this?.", but this is Javascript, not Java, you were talking about. The two are completely different technlogies, so please don't confuse them.

 

Thanks.

Let us know if you have any other questions.

  • Upvote 1
Link to comment
Share on other sites

First things first, please increase the size of your code and/or place it within code tags. You can do this easily by editing your original post.

Please do it.

How many times have people on this forum asked Paul_Blackpool to amend how he posts threads? We're not asking because we're being difficult, we're asking because its about keeping the forum working in the way it was originally intended. As long as people keep responding to his posts despite the ridiculous amount of tiny coding, he is not going to change how he posts - why should he.

 

@Paul_Blackpool, if you don't know how to preview/format your posts just ask - you'll engender a lot more good will.

 

Sorry if this sounds harsh but this is a good forum and I'd hate to see it go the way of many others through carelessness.

  • Upvote 1
Link to comment
Share on other sites

Thanks HartleySan that’s a big help for me.

margux I understand what you’re saying. I’m new to this and I had to start learning because I was let

down by people who were supposed to be website developers.

 

I am using a program called wisywig web editor because it’s easy. It’s like building the pages in word and has drag and drop functions, however it only generates the code and you can’t edit it from within the program. I have noticed that when you create a blank page it does have a lot of little code and I am not really sure what it means half of the time. I think I will study it tonight and see if I can get my head round it.

 

HartleySan has always been very helpful when I have got stuck and tells me how to do things in a way that I can understand.

 

I will get better with time (Promise)

Link to comment
Share on other sites

I'm glad I can help Paul (that's why I come around so regularly), but please understand, it takes little to no effort to help us out immensely by better formatting your posts.

And I do agree with margaux that I shouldn't be encouraging your behavior by responding to your posts even though you don't follow the forum guidelines.

As a result, in the future, unless you can properly format your code, I will not response to your posts.

It's not much to ask, really.

 

Also, please don't use super-small text in your posts, like the last one.

Please just use the normal font and size and put your code within

 tags, and everyone will be happy.

Thank you.

  • Upvote 2
Link to comment
Share on other sites

Just so I can try and get the post right how should the script that I posted look. That would help me as then I will learn which parts of the script I need to display.

 

Paul, check post #2 in this thread, how the code looks will be done automatically, you just have to remember to put the code tags around your code.

 

[ code] [ /code]

 

less space between opening square bracket and code /code.

Link to comment
Share on other sites

Thanks Paul_Blackpool and HartleySan for taking my comments in the spirit they were intended. I like to help on this forum because I learn so much from it that I want to give something back and because it is a great way to consolidate my own learning and understanding of various concepts.

HartleySan has always been very helpful when I have got stuck and tells me how to do things in a way that I can understand.
Other people will help you more if you make your posts readable:

 

1. Before you click 'Post', click on 'More Reply Options' to show you a preview of your post.

2. When you want to paste some code into a post, first click on the icon <>, this will bring up a modal box and you can paste your code in the box. It will then be formatted nicely like in HartleySan's post.

Also, please don't use super-small text in your posts, like the last one.

3. use the formatting options to change the size of your text so it is more readable.

4.Try hovering your cursor over the various icons above the edit post panel and you'll see that there are a lot of formatting options to help you.

5. If you're not sure how to edit the post, just ask. When I first started visiting forums, I didn't know how to use code tags but try different options and you'll find out.

  • Upvote 1
Link to comment
Share on other sites

Well I think I have just created my first website. I have not yet implimented the checkboxes and I have to create another area of the site to post and search jobs (That should be challenging) but all in all for a first attempt, well I think its OK.

 

Would apreciate you more experianced lads taking a look and see if I have obviously done anything wrong.

 

The site address is:

 

http://www.trsb.co.uk/new

 

I would like to thank you all for your help and advice.

Link to comment
Share on other sites

Very good for a first website.

There are of course things that can be improved, but overall, while it doesn't seem to be fully functioning yet, it is at least clear what the objective of the site is as well as how to use it.

Keep up the good work, and please remember what margaux said above when you make posts.

Link to comment
Share on other sites

  • 3 months later...

how about handling multiple submit buttons in php?

I have come across scripts that use:

isset($_POST['submit'])

 

as well as code that uses:

$_SERVER['REQUEST_METHOD']=='POST'

 

which is better to use? my situation is having two submit button in one php script. since that i cant use the 2nd one in verifying what form is being submitted should this be mean the first one is better?

Link to comment
Share on other sites

jabsalud, there are two types of pages with multiple submit buttons:

1) Multiple forms on a page, each with a submit button, and

2) One form on a page with multiple submit buttons.

 

Either way, like benjamin said, the easiest way to handle it is to give each submit button a different name and then test for the existence (i.e., the submission) of a submit button with a certain name.

Link to comment
Share on other sites

 Share

×
×
  • Create New...