Hey guys, I was curious if someone would be able to provide advice on how to do this... Basically I want to create a simple web-form that has a bunch of questions and allows the user to answer them. Then it has to pass the list of questions under one "name" element. Here is what I have so far:

<form name="bulletinForm" method="post" target="_self" action="http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.edit">
            <input type="hidden" value="0" name="groupID">
            <input class="htmlgenscom" type="hidden" maxLength="50" size="1" value="The Greatest Survey Ever!" name="subject">
            
            <p>Question 1?</p>
            <textarea class="htmlgenscom" name="body" type="hidden" style="width: 0px; height: 0px;" rows="1" cols="20"><ul><li><b>Question 1?</b><br></textarea>
            <input type="text" name="body" size="30" maxlength="100" rows="1" cols="20">
            <p>Question 2</p>
            <textarea class="htmlgenscom" name="body" type="hidden" style="width: 0px; height: 0px;" rows="1" cols="20"></li><li><b>Question 2?</b><br></textarea>
            <input type="text" name="body" size="30" maxlength="100" rows="1" cols="20">
            
            <textarea class="htmlgenscom" name="body" type="hidden" style="width: 0px; height: 0px;" rows="1" cols="20"></li></ul></textarea><br><br>
            <input type=submit class=submit value="Post the Survey on Myspace!" name="submit0" target="_blank">
        </form>

Basically it passes these elements to the Myspace bulletin form to automatically post the questions and answers in the users bulletin. It works pretty well how I set it up, except around each answer (the "input type="text"" boxes) there is a comma when you see the output. Alittle confusing I know. You can see a example here:

Hope someone can help!

Dani AI

Generated

Short answer: the stray commas come from submitting the same field name repeatedly. When the bulletin script receives multiple body values it treats them as an array and joins them with commas. Fix by sending a single body field whose value is the entire assembled HTML string (build that string on the client or in PHP), then post that one field to the bulletin endpoint.

A simple, robust workflow (recommended):

  • Name your inputs as arrays in the first form (question[] and answer[]) so PHP can iterate them easily.
  • In the PHP receiver, loop the arrays, sanitize with htmlspecialchars, build one ul/li string, then output a form that contains a single hidden textarea named body whose contents are that string.
  • Auto-submit that form with a tiny bit of JavaScript so the user does not need to click again.

Example PHP build + auto-submit (adapt to your action URL and labels):

// assemble
$qs = $_POST['question'] ?? array();
$as = $_POST['answer']   ?? array();
$items = array();
$max = min(count($qs), count($as));
for ($i = 0; $i < $max; $i++) {
    $q = htmlspecialchars(trim($qs[$i]), ENT_QUOTES, 'UTF-8');
    $a = htmlspecialchars(trim($as[$i]), ENT_QUOTES, 'UTF-8');
    $items[] = "<li><b>{$q}</b><br>{$a}</li>";
}
$body = "<ul>" . implode("", $items) . "</ul>";

Then output a form with one textarea name="body" containing $body and this JS to auto-submit:

<form id="postToSite" method="post" action="(MySpace bulletin endpoint)">
  <input type="hidden" name="groupID" value="0">
  <input type="hidden" name="subject" value="Survey">
  <textarea name="body" style="display:none;"><?php echo $body; ?></textarea>
</form>
<script>document.getElementById('postToSite').submit();</script>

Notes and cautions:

  • Don’t use type="hidden" on a textarea — hide it with CSS instead.
  • Count questions with count($_POST['question']) (or min(count(...),count(...)) when pairing).
  • Escape user input to avoid injection and broken markup.
  • Auto-posting requires the user to be logged into the target site in their browser; some sites also use CSRF tokens or filters that block automated posts.
  • For PHP-specific syntax/quoting issues, use heredoc/nowdoc or close PHP to emit raw HTML; was right that very specific PHP debugging may be better in the PHP forum.

Recommended Answers

All 4 Replies

I am trying to make it in php so I can "build the textbox" in a php file then have the user submit it. I have two questions however:

1. I am getting lots of random php errors like "unexpected T-string" of which I can see no error...

2. Could I make the php file automatically submit the "textbox" or information to the myspace post bulliton form? Rather than making the user press a second button?

Here is my code (this is only the code within the body tags...):

First page:

<div align="center"><form name="bulletinForm" method="post" target="_self" action="submit.php">
                        
            <p>Who is the last person you high-fived?: 
            <textarea class="htmlgenscom" name="question1" type="hidden" style="width: 0px; height: 0px;" rows="1" cols="20">Who is the last person you high-fived?</textarea>
            <input type="text" name="answer1" size="30" maxlength="100" rows="1" cols="20"></p>
            
            <p>If you were drafted into a war, would you survive?: 
            <textarea class="htmlgenscom" name="question2" type="hidden" style="width: 0px; height: 0px;" rows="1" cols="20">If you were drafted into a war, would you survive?</textarea>
            <input type="text" name="answer2" size="30" maxlength="100" rows="1" cols="20"></p>
            
            <input type="submit" value="Post this survey on your Myspace!" name="submit">
        </form><div align="center">

Here is the php "submit" page:

<?php
$question1 = $_POST['question1'];
$question2 = $_POST['question2'];
$answer1 = $_POST['answer1'];
$answer2 = $_POST['answer2'];
echo ("<div align="center"><form name="bulletinForm" method="post" target="_self" action="bulletin.myspace.com\index.cfm?fuseaction=bulletin.edit"><input type="hidden" value="0" name="groupID"><input class="htmlgenscom" type="hidden" maxLength="50" size="1" value="The Greatest Survey Ever" name="subject"><br><textarea class="htmlgenscom" name="body" type="hidden" rows="1" cols="20">");
echo ($question1 . ": " . $answer1 . "<br>" . $question2 . ": " . $answer2);
echo ("</textarea><br><br><input type="submit" class="submit" value="Press here to Submit!" name="submit" target="_blank"></form></div>");
?>

A live example can be found here:

Ok, I fixed my unexpected T_string error, but how would I go about making the "submit.php" file automatically submit the text box to the myspace post bulleton?

And another question, how can I make my php-submit form automatically count how many questions and answers are passed onto it?

This isn't the PHP forum, and your project is a bit too involved for the casual volunteer to help out. Forums such as this are best used for very specific questions about a particular aspect of HTML/CSS/JavaScript.

Wow... I am so sorry. I seriously thought that I had clicked the php forum. Crap. Ok, well, I have fixed most of this. Thanks for the reminder. ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.