0

I'm building a simple tool that will assemble a string based on HTML form input.

However, two variables are not being pulled into the string as expected.

Here is the HTML form:

<form action="stringmaker.php" method="post">
<label for="subline">Subject line:</label>
<input type="text" id="subline" name="subline" size="30" /><br /><br />

<label for="emailtype">Email Type</label>
<select name="emailtype">
<option value="advocacy" selected>Advocacy</option>
<option value="fundraising">Fundraising</option>
<option value="newsletter">Newsletter</option>
<option value="event">Event</option>
<option value="cultivation">Cultivation</option>
</select><br /><br />

<label for="campaign">Campaign</label>
<select name="campaign">
<option value="campaign1" selected>Campaign 1</option>
<option value="campaign2" selected>Campaign 2</option>
<option value="campaign3" selected>Campaign 3</option>
<option value="campaign4" selected>Campaign 3</option>
</select>

<h3>Audience Information</h3>
<label for="audiencetype">Audience Type</label>
<select name="audiencetype">
<option value="noaudiencetype" selected>None</option>
<option value="interestgroup">Interest Group</option>
<option value="donors">Donors</option>
<option value="actiontakers">Action-Takers</option>
</select><br /><br />

<label for="geo">Audience Geography</label>
<select name="geo">
<option value="national" selected>National</option>
<option value="state">State</option>
<option value="district">District</option>
<option value="city">City</option>
</select><br /><br />

<label for="statename">State</label>
<select name="statename">
<option value="ak" selected>Alaska</option>
<option value="al">Alabama</option>
<option value="az">Arizona</option>
<option value="dc">Washington, D.C.</option>
</select><br /><br />

<input type="submit" value="Go" name="submit" />

And here is the PHP:

<?php
$subline = $_POST['subline'];
$emailtype = $_POST['emailtype'];
$campaign = $_POST['campaign'];
$audiencetype = $_POST['audiencetype'];
$geo = $_POST['geo'];
$statename = $_POST['statename'];

echo "<p>Here's your string!<br>";
echo $subline,"|",$emailtype,"|",$campaign,"|",$audiencetype,"|",$geo,"|",$statename;
?>

The output is missing the first ($subline) and fifth ($geo) variables, and I can't figure out what is different with those.

Thanks for your help.

11
  • 2
    print_r($_POST); show us the results Commented Sep 4, 2014 at 2:45
  • 1
    Try echo $subline."|".$emailtype."|".$campaign."|".$audiencetype."|".$geo."|".$statename; dots are to concatenate, not commas. Plus, your question's code is missing a closing </form> tag. Commented Sep 4, 2014 at 2:49
  • 1
    I think @Fred-ii- is correct Commented Sep 4, 2014 at 2:50
  • Are you also sure that you have closing tag for form? Commented Sep 4, 2014 at 2:51
  • Sorry, @Fred-ii- is incorrect. echo allows multiple arguments, and it prints them all. Commented Sep 4, 2014 at 2:55

1 Answer 1

1

Edit:

As it stands, both dots and commas are acceptable, my mistake.
Your form is/was missing </form> tag, least from your originally posted code.

Everything echoe'd correctly in my test.

The only thing I can come up with to explain why $subline is empty, is that it hasn't been filled. Everything else checks out.

I also noticed that you also have all of these as selected

<option value="campaign1" selected>Campaign 1</option>
<option value="campaign2" selected>Campaign 2</option>
<option value="campaign3" selected>Campaign 3</option>
<option value="campaign4" selected>Campaign 3</option>

Sidenote: You have 2x Campaign 3, but that wouldn't affect anything.

There should only be one.

<option value="campaign1" selected>Campaign 1</option>
<option value="campaign2">Campaign 2</option>
<option value="campaign3">Campaign 3</option>
<option value="campaign4">Campaign 3</option>

(Fixed it to be Campaign 4)

<option value="campaign1" selected>Campaign 1</option>
<option value="campaign2">Campaign 2</option>
<option value="campaign3">Campaign 3</option>
<option value="campaign4">Campaign 4</option>

One of my test results:

Here's your string!
test|fundraising|campaign3|noaudiencetype|district|ak

original answer:

Use dots/periods to concatenate, not commas.

echo $subline."|".$emailtype."|".$campaign."|".$audiencetype."|".$geo."|".$statename;

Plus, your question's code was missing a closing </form> tag.

Sign up to request clarification or add additional context in comments.

4 Comments

Read the documentation. The syntax is echo $arg1, $arg2, $arg3, ...
@Barmar Yes, my mistake. I tested with both commas and dots and it worked. I think it's only the missing </form> tag.
Why would that omit only subline and geo?
@Barmar That's what I'm trying to find out. If I can't find the actual problem, I will delete my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.