Welcome to WebmasterWorld Guest from 34.228.143.13
Okay I'm total new at php. I wanted a form, so I got one made at thesitewizard.com which I then modified.
There are some places on my form where I don't want input fields, instead I want a drop down menu with options to choose from there.
<stupid_question>Would it help to post code, or do people not usually do that for php.</stupid_question>
thanx a mill,
animgirl
Is it some form of dynamic drop-down you want? Ie; information pulled from a database or such?
Or is it a standard drop-down with options you specify in the page?
And from the TOS:
Excessive code dumps will be edited. We appreciate that it's often neccessary to post code, just keep it very short and simple please.
wruk999
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$purpose =$_POST['purpose'] ;
$content =$_POST['content'] ;
$target_audience =$_POST['target_audience'] ;
$existing_graphics =$_POST['existing_graphics'] ;
$existing_url =$_POST['existing_url'] ;
$budget = $_POST['budget'] ;
$see_in_a_site = $_POST['see_in_a_site'] ;
$additional_comments = $_POST['additional_comments'];$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) ¦¦ empty($email) ¦¦ empty($purpose) ¦¦ empty($content) ¦¦ empty($budget)) {
header( "Location: $errorurl" );
exit ;
}
Howzat?
Okay, is this form emailed to you then?
I take it that that part of it is processed after the code you posted? No-probs.
On your form page, you want something like:
<select name="title">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
<option value="Miss">Miss</option>
<option value="Dr">Dr</option>
<option value="Choose" selected>Please select..</option>
Okay, this form select is an example of titles.
Then in you php you will need:
$title = $_POST['title'];
Then you can use the $title variable in whatever processing your form does ;)
HTH,
wruk999
Okay, that works great :)
o thank you thank you.
Now i'm trying to get the html right.
I'm using xhtml, which makes it a bit different and no tables, just divs.
Here's how I've set up my html:
<form action="online_consultation_form.php" method="post">
<div>
check it baby:<br />
<select name="title">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
<option value="Miss">Miss</option>
<option value="Dr">Dr</option>
<option value="Choose" selected>Please select..</option> <br />
<br />
Name:<br />
<input type="text" name="name" size="25" />
<br />
<br />
Email address:<br />
<input type="text" name="email" size="25" />
</div>
</form>
{shortened for convenience} This is what it looks like:
The name section is overtaken by the new box.
Any ideas? :)
animgirl
[edited by: jatar_k at 8:28 pm (utc) on July 11, 2003]
[edit reason] no personal urls thanks [/edit]
The bit with it emailing to you - you can post it, just change domains and email addy's etc to: example@example.com or similar. This means we can still see the function being processed.
Could you posdt the sending to ou bit, as it may need to be configured to show your select list.
The layout on the page, I cannot really help with. That is something worth asking either in a different forum cat, or using trial and error to fix.
wruk999
// $mailto - set to the email address you want the form
// sent to, eg
//$mailto= "example@example.com" ;$mailto = 'example@example.com' ;
// $subject - set to the Subject line of the email, eg
//$subject= "Spiffy Form Thingie" ;
$subject = "Spiffy Form Thingie" ;
// the pages to be displayed, eg
//$formurl= "http://www.example.com/spiffy_form_thingie.htm" ;
//$errorurl= "http://www.example.com/error.htm" ;
//$thankyouurl= "http://www.example.com/thankyou.htm" ;
$formurl = "http://www.example.com/spiffy_form_thingie.htm" ;
$errorurl = "http://www.example.com/error.htm" ;
$thankyouurl = "http://www.example.com/thankyou.htm" ;
I assume you build the message from your $_POST values and then use it in the mail function something like this
mail [ca3.php.net]($mailto,$subject,$message,$headers);
All you need to do is add the values and formatting for your form elements to $message.
You have this right now
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$purpose =$_POST['purpose'] ;
$content =$_POST['content'] ;
$target_audience =$_POST['target_audience'] ;
$existing_graphics =$_POST['existing_graphics'] ;
$existing_url =$_POST['existing_url'] ;
$budget = $_POST['budget'] ;
$see_in_a_site = $_POST['see_in_a_site'] ;
$additional_comments = $_POST['additional_comments'];
Just add a new line that has the name of the radio button or you could change this to a loop
$message = "";
foreach ($_POST as $key => $value) {
$message .= $key . ": " . $value . "\n";
}
You could then tweak that to add the formatting to each element or skip ones that you don't want included.
[edited by: jatar_k at 7:00 pm (utc) on July 22, 2003]
There are 3 types of loops that I use on a regular basis
foreach [ca.php.net]
while [ca.php.net]
for [ca.php.net]
These are Control Structures [ca.php.net].
A loop will do something over and over again, why and when it stops is different for each type of loop. The documentation linked to above will explain each in detail.
As for your specific situation I threw this at you
$message = "";
foreach ($_POST as $key => $value) {
$message .= $key . ": " . $value . "\n";
}
You have all those lines putting $_POST vars into named vars and then I imagine somewhere you take all of those and put them into a message variable and then send them off to the mail function.
Instead you can use a foreach loop. What that does is make it very simple to iterate through an array and take action (or not) on each individual value. So the little loop I threw at you says
1. For each value in the $_POST array take the name of the element from your form and put it in the variable $key. Then take the value submitted with that form element and put it into the variable $value.
2. Add the name and the value into the message variable, with some formatting.
3. Keep doing this until there are no more values left.
This just makes for shorter, easier to maintain code. Another option would be to use extract($_POST) [ca.php.net] to get the variables out of the $_POST array.
As far as how the radio buttons will look, they look like html radio buttons how about
Radio Buttons, Checkboxes, and More [hotwired.lycos.com]