?
Solved

adding second value to contact-form subject field

Posted on 2011-04-19
23
Medium Priority
?
311 Views
Last Modified: 2012-05-11
Hi,

First of all, my contact-form works correct. In the code the subject field's value is =
value="{$subject[2]}"

But i would also like to add the possibility to get the subject from the url, if someone comes from a page with a link to the contact-form, like this: echo $_GET['subject'])
with the url: contactform.php?subject=test

How would i do this, so that the subject field works in both ways (manually entered or filled via the url?

Thanks
0
Comment
Question by:peps03
  • 13
  • 10
23 Comments
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35424559
How about something like this:
if(isset($_GET['subject']){
	$subject = $_GET['subject'];	   
}else{
	$subject = $subject[2];
}
//rest of your code

Open in new window

0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35424564
Sorry, use this.. I missed a prin
if(isset($_GET['subject'])){
        $subject = $_GET['subject'];       
}else{
        $subject = $subject[2];
}
//rest of your code

Open in new window

0
 

Author Comment

by:peps03
ID: 35424723
Thanks for your reaction galexander07!

My Dreamweaver gives me errors though, not in words, but red marked line numbers.

Could that be because the code is in these tags:

<<<EOD   ..................... EOD;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35424736
Yes, Dreamweaver is not a good PHP code editor... great because of design view for html, but it does not support <<<EOD
0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35424741
As long as the code works when run through the browser... you are good
0
 

Author Comment

by:peps03
ID: 35424768
Also online, i get this error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in xxxxxx.nl/contactform/index.php on line 262
0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35424774
Can you post the section that your question is about ... I can fix it for ya
0
 

Author Comment

by:peps03
ID: 35424801
<?
//was:

<input type="text" name="{$subject[1]}" value="{$subject[2]}" size="40" onKeyPress="return event.keyCode!=13" />

// should be:
<input type="text" name="{$subject[1]}" value="{".if(isset($_GET['subject'])){$subject = $_GET['subject'];}else{$subject = $subject[2];}."}" size="40" onKeyPress="return event.keyCode!=13" />

?>

Open in new window

0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35424860
Should be:

<input type="text" name="{$subject[1]}" value="{".if(isset($_GET['subject'])){echo $_GET['subject'];}else{echo $subject[2];}."}" size="40" onKeyPress="return event.keyCode!=13" />

Do you have to use <<<EOD? I am not a big fan. and I think it could be messing with your code
0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35424874
in straight HTML with PHP embedded I would use
<input type="text" name="<?= $subject[1]; ?>.'" value="<? if(isset($_GET['subject'])){echo $_GET['subject'];}else{echo $subject[2];} ?>" size="40" onKeyPress="return event.keyCode!=13" />';

Open in new window

0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35424881
Without the semi colon on the end actually
0
 

Author Comment

by:peps03
ID: 35424943
Hmm still no succes.. same errors

I think i have to use <<<EOD
because the rest of the form is also in it..
0
 

Author Comment

by:peps03
ID: 35425035
maybe i should try to remove the <<<EOD

and make all the links like this: <?= $subject[1]; ?>
0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35425053
Can you postthe whole form?
0
 

Author Comment

by:peps03
ID: 35425100
This is the original code, without the subject modifications.
this is the part between:
<<<EOD
and
EOD;
<?


echo <<<EOD

<form method="post" class="cForm">
<table style="width:{$form_width}; background-color:{$form_background}; border:{$form_border_width} {$form_border_style} {$form_border_color}; padding:0px; font-size:{$font_size};" class="contactForm">
<tr>
<td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding}; font-size:110%; font-weight:normal;"><b>Alle velden gemarkeerd met een * zijn verplicht.</u><br /><br /></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:normal; {$voornaam[3]}">{$voornaam[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$voornaam[1]}" value="{$voornaam[2]}" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:normal; {$achternaam[3]}">{$achternaam[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$achternaam[1]}" value="{$achternaam[2]}" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:normal; {$woonplaats[3]}">{$woonplaats[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$woonplaats[1]}" value="{$woonplaats[2]}" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:normal; {$telefoonnummer[3]}">{$telefoonnummer[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$telefoonnummer[1]}" value="{$telefoonnummer[2]}" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:normal; {$email[3]}">{$email[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$email[1]}" value="{$email[2]}" size="40" onKeyPress="return event.keyCode!=13" /> {$email[4]}</td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:normal; {$subject[3]}">{$subject[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$subject[1]}" value="{$subject[2]}" size="40" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:normal; {$message[3]}">{$message[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><textarea name="{$message[1]}" cols="40" rows="6">{$message[2]}</textarea></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding};">&nbsp;</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><img id="captcha" src="contactform/securimage_show.php" alt="CAPTCHA Image" /></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:normal; {$code[3]}">{$code[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$code[1]}" size="10" maxlength="5" /> {$code[4]}
<br /><br />(Vul aub de tekst uit het plaatje hierboven in.<br />De tekst is niet hoofdletter gevoelig.)<br />
<a href="#" class="page" onclick="document.getElementById('captcha').src = 'contactform/securimage_show.php?' + Math.random(); return false">Klik hier als u de tekst niet goed kan lezen.</a>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding};"><br /><br />&nbsp;{$GLOBALS['error_message']}</td>
</tr>
<tr>
<td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding};"><br /><input type="submit" name="submit" value="Verzenden" />&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="Formulier wissen" /></td>
</tr>
</table>
</form>
EOD;
?>

Open in new window

0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35425188
Try <<<EOT ................EOT; maybe? instead of <<< EOD
0
 

Author Comment

by:peps03
ID: 35425335
no, then all goes red again, now it isn't...
0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35425460
> maybe i should try to remove the <<<EOD

I like that idea :)
0
 
LVL 19

Accepted Solution

by:
Greg Alexander earned 2000 total points
ID: 35425496
I think this may work, plus you can now use design view in Dreamweaver!
<?


//get outta php all together
?>
<form method="post" class="cForm">
<table style="width:<?= $form_width;?>; background-color:<?= $form_background;?>; border:<?= $form_border_width;?> <?= $form_border_style;?> <?= $form_border_color;?>; padding:0px; font-size:<?= $font_size;?>;" class="contactForm">
<tr>
<td colspan="2" style="text-align:left; vertical-align:middle; padding:<?= $cell_padding;?>; font-size:110%; font-weight:normal;"><b>Alle velden gemarkeerd met een * zijn verplicht.</u><br /><br /></td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>; font-weight:normal; <?= $voornaam[3];?>"><?= $voornaam[0];?></td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><input type="text" name="<?= $voornaam[1];?>" value="<?= $voornaam[2];?>" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>; font-weight:normal; <?= $achternaam[3];?>"><?= $achternaam[0];?></td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><input type="text" name="<?= $achternaam[1];?>" value="<?= $achternaam[2];?>" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>; font-weight:normal; <?= $woonplaats[3];?>"><?= $woonplaats[0];?></td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><input type="text" name="<?= $woonplaats[1];?>" value="<?= $woonplaats[2];?>" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>; font-weight:normal; <?= $telefoonnummer[3];?>"><?= $telefoonnummer[0];?></td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><input type="text" name="<?= $telefoonnummer[1];?>" value="<?= $telefoonnummer[2];?>" onKeyPress="return event.keyCode!=13" /></td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>; font-weight:normal; <?= $email[3];?>"><?= $email[0];?></td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><input type="text" name="<?= $email[1];?>" value="<?= $email[2];?>" size="40" onKeyPress="return event.keyCode!=13" /> <?= $email[4];?></td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>; font-weight:normal; <?= $subject[3];?>"><?= $subject[0];?></td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><input type="text" name="<?= $subject[1]; ?>.'" value="<? if(isset($_GET['subject'])){echo $_GET['subject'];}else{echo $subject[2];} ?>" size="40" onKeyPress="return event.keyCode!=13" />';</td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>; font-weight:normal; <?= $message[3];?>"><?= $message[0];?></td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><textarea name="<?= $message[1];?>" cols="40" rows="6"><?= $message[2];?></textarea></td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;">&nbsp;</td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><img id="captcha" src="contactform/securimage_show.php" alt="CAPTCHA Image" /></td>
</tr>
<tr>
<td style="width:<?= $left_col_width;?>; text-align:left; vertical-align:top; padding:<?= $cell_padding;?>; font-weight:normal; <?= $code[3];?>"><?= $code[0];?></td>
<td style="text-align:left; vertical-align:top; padding:<?= $cell_padding;?>;"><input type="text" name="<?= $code[1];?>" size="10" maxlength="5" /> <?= $code[4];?>
<br /><br />(Vul aub de tekst uit het plaatje hierboven in.<br />De tekst is niet hoofdletter gevoelig.)<br />
<a href="#" class="page" onclick="document.getElementById('captcha').src = 'contactform/securimage_show.php?' + Math.random(); return false">Klik hier als u de tekst niet goed kan lezen.</a>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:left; vertical-align:middle; padding:<?= $cell_padding;?>;"><br /><br />&nbsp;<?= $GLOBALS['error_message']; ?></td>
</tr>
<tr>
<td colspan="2" style="text-align:left; vertical-align:middle; padding:<?= $cell_padding;?>;"><br /><input type="submit" name="submit" value="Verzenden" />&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="Formulier wissen" /></td>
</tr>
</table>
</form>
<?
//rest of your code
?>

Open in new window

0
 

Author Comment

by:peps03
ID: 35425601
hmm oke.. the form works.. but..

the subject is not sent with the message. in neither way..
0
 

Author Comment

by:peps03
ID: 35425606
thought this was an easy question.. pff
0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35426037
Hmm... when you view the source of the code before you submit are the values there?
0
 

Author Closing Comment

by:peps03
ID: 35426102
good tip! it now works!

there was a typo in here: name="<?= $subject[1]; ?>.'"    // note the marked code

Thank you very much for your help galexander07!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question