Jump to content

Using a form to specify include() location


Simplicity

Recommended Posts

Hi guys, to start with, thanks for your help previously.

I have a form with a drop down list of team names which looks like:

[code] <form action="$pageselect" method="post" name="TeamName" id="TeamName">
      Select Team Name
      <select name="TeamName">
        <option>Team1</option>
        <option>Team2</option>
        <option>Team3</option>
        <option>Team4</option>
        <option>Team5</option>
        <option>Team6</option>
      </select>&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="submit" name="Submit" value="Submit">[/code]

When submitted I want to post the team name to a variable at the top of the page defined here:

[code]<?php
$pageselect = $_POST['TeamName'];
?>[/code]

And then dynamically update a <div> tage at the bottom of the page with that teams table (a .php doc stored under the team name) which I've written like so...

[code]  <?php
 
  if(ISSET($_POST['submitted'])){
  include($pagename.php);
  }else{
  echo "Please use the dropdown menu above to select your team name";}
  ?>
[/code]

As the error I'm getting is: The requested URL /$pageselect was not found on this server. I'm guessing either my team name is not getting passed across from my form or my include is wrong.  Neither my php book or my html book have a simliar scenario that I can work from.  Any suggestions?  Other than maybe I should take up knitting or playing with kittens.
Link to comment
https://forums.phpfreaks.com/topic/28890-using-a-form-to-specify-include-location/
Share on other sites

Your problem is here:
[code]<form action="$pageselect" method="post" name="TeamName" id="TeamName">[/code]
The value for the action attribute should be the name of script that processes the information from the form.


Ken
As
[code]<?php
$pageselect = $_POST['TeamName'];
?>[/code]

was originally included at the top of the page, I moved it to a new file named formhandle1.php and saved it.

Changed my form to [code] <form action="formhandle1.php" method="post" name="TeamName" id="TeamName">[/code]

Left everything else as is, (my 'if' statement remaining in the original <div> tag on the page under the form)

When clicking submit I now just get a blank page.  :(
Seems as though your doing something difficult for an easy task.

Say your form is on a page that has already included a file..

Make this form..

<form method='post'>
<select name='teamname'>
<option value='bla'>Bla</option>
</select>
<br />
<input type='submit' name='changepage' value='GO to Whatever' />
</form>


Now edit wherever it is in the page that is including a file to this:

[code]
if($_POST['changepage']){
include($_POST[teamname]."php");
}else{
include('default_include.php');
}
[/code]
Thanks.

I think that almost worked.  :)

Warning: main(Unionistphp): failed to open stream: No such file or directory in etc etc  referring to line 57 which reads

[code] include($_POST[TeamName]."php");[/code]

Its not putting the dot between the filename and extension?
[quote author=Simplicity link=topic=116744.msg475868#msg475868 date=1164834188]
Thanks.

I think that almost worked.  :)

Warning: main(Unionistphp): failed to open stream: No such file or directory in etc etc  referring to line 57 which reads

[code] include($_POST[TeamName]."php");[/code]

Its not putting the dot between the filename and extension?
[/quote]

I am very sorry, jocka is correct:
make it this, i messed up on the include string

if($_POST['changepage']){
include($_POST[teamname].".php");
}else{
include('default_include.php');
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.