Jump to content

Form help - forgot my book!!


mfindlay

Recommended Posts

Sorry to bother you guys with this, I am trying to pass a variable from a drop down list into the action url with no success....code below

<?php
echo "<form method=\"post\" action=\"http://www.mysite.asp?r=12345" . $case . "678\">\n";
echo "<select name=\"case\">\n";
echo "<option>---------</option>\n";
echo "<option value=\"case1\">Case 1</option>\n";
echo "<option value=\"case2\">Case 2</option>\n";
echo "<option value=\"case3\">Case 3</option>\n";
echo "<option value=\"case4\">Case 4</option>\n";
echo "</select>\n";
echo "<input type=\"submit\" value=\"Submit\" />\n";
echo "</form>\n";
?>

 

where am i going wrong?

 

Thanks

Link to comment
Share on other sites

You can't say the action before the $case variable has been declared, try this instead:

 

<?php
echo "<form method=\"get\" action=\"http://www.mysite.asp\">\n";
echo "<select name=\"case\">\n";
echo "<option>---------</option>\n";
echo "<option value=\"12345case1678\">Case 1</option>\n";
echo "<option value=\"12345case2678\">Case 2</option>\n";
echo "<option value=\"12345case3678\">Case 3</option>\n";
echo "<option value=\"12345case4678\">Case 4</option>\n";
echo "</select>\n";
echo "<input type=\"submit\" value=\"Submit\" />\n";
echo "</form>\n";
?>

Link to comment
Share on other sites

If global variables is off (which it should be for security purposes,) $case isn't defined.

 

If the receiving file (in the action attribute) was PHP, the $case variable you are referring to would be in the $_POST array.  So $case would actually be $_POST['case'] in the file you are sending the form to.  There's no need to put $case into the url like that (if I understand correctly.)

 

Also, www.mysite.asp isn't a valid URL (at least I don't think it is..it should be www.mysite.com (or net/org/etc) and then /file.asp.)

 

This is what it should look like:

echo "<form method=\"post\" action=\"http://www.mysite.com/file.asp?r=12345678\">\n";

 

Calling echo so many times will slow down your script.  Use only one echo and encase everything in quotes.  Use single quotes, too.  They're slightly faster and you're already writing code geared toward them.  ;)

 

I hope I'm not too confusing, and good luck!

Link to comment
Share on other sites

 

Thanks all, this script is to call specified reports from an assessment system, so to call it via url it would be

 

http://assessment_system.ac.uk/report.asp?r=012345case1678

 

so I thought I could pass the $case variable through via drop down list, I'll just have to create processing script and collect the variable that way before sending to the assessment system...

 

<?php
echo "<form method=\"post\" action=\"process.php\">\n";
echo "<select name=\"case\">\n";
echo "<option>---------</option>\n";
echo "<option value=\"case1\">Case 1</option>\n";
echo "<option value=\"case2\">Case 2</option>\n";
echo "<option value=\"case3\">Case 3</option>\n";
echo "<option value=\"case4\">Case 4</option>\n";
echo "</select>\n";
echo "<input type=\"submit\" value=\"Submit\" />\n";
echo "</form>\n";
?>

 

and then...process.php

 

<?php
$case=$_POST['case'];

header('Location: http://assessment_system.ac.uk/report.asp?r=012345' .$case . '678/');
?>

 

 

Cheers

Link to comment
Share on other sites

Hi Guys,

 

sorry to bother you about this again,I'll exaplain more in more detail what I am trying to do...

We have an assessment system which will give student reports in certain formats, I need to filter the reports by case or by topic (which the system won't do!). So to do it manualy for 1 report I would right a form...

 

<form method="post" action="assessment_system_url?report=12345case1678"  target="newWin">
<input type="hidden" name="Name" id="Text1" value="name" />
<input type="hidden" name="Password" ID="Password1" value="password" />
<input type="submit" value="View Assessment Progress" onclick="doSubmit();"/>
</form

 

So the ideal method would be to use the form below and change the action urll..

 

echo '<form method="post" action="assessment_system_url?report=12345' . $case . '1678"  target="newWin">
<input type="hidden" name="Name" id="Text1" value="name" />
<input type="hidden" name="Password" ID="Password1" value="password" />
<select name="case">
<option>---------</option>
<option value="case1">Case 1</option>
<option value="case2">Case 2</option>
<option value="case3">Case 3</option>
<option value="case4">Case 4</option>
</select>
<input type="submit" value="Submit" />
</form>';

<h1>View quiz results by topic</h1>


echo '<form method="post" action="assessment_system_url?report=12345' . $subject '678">
<input type="hidden" name="Name" id="Text1" value="name" />
<input type="hidden" name="Password" ID="Password1" value="password" />
<select name="subject">
<option>---------</option>
<option value="anatomy">Anatomy</option>
<option value="pathology">Pathology</option>
<option value="physiology">Physiology</option>
</select>
<input type="submit" value="Submit" />
</form>';

 

which doen't work as the action url can't be changed dynamically like this, the other option is to use the method in my previous post, write a form and have a process.php file

 

<?php
$case = $_POST['case'];
$subject = $_POST['subject'];

if ($case == true)
header('Location: http://assessment_url?report=12345' . $case . '678');
if ($subject == true)
header('Location: http://assessment_url?report=12345' . $subject . '678');
?>

 

But I need to pass 3 variables to the assessment system...username and password, which can't be embedded in the url, and either $case or $subject which needs to be passed via url.

 

Any ideas??

Cheers.

Link to comment
Share on other sites

try this ...

 


<?php
$case = $_POST['case'];
$subject = $_POST['subject'];

if ($case == true)
header('Location: http://assessment_url?report=12345&username='.$username.'&password='.$password . $case . '678');
if ($subject == true)
header('Location: http://assessment_url?report=12345&username='.$username.'&password='.$password . $subject . '678');
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.