Jump to content

switch form actions? not working


dflow

Recommended Posts

i want on submit to go to different pages according to the CatID

 

<?php $CatID=$_GET['CatID'];
if (isset($CatID)) {

}
switch ($CatID)
{
    case 1:
echo '<form action="new-product-full-page-citycountry.php" method="get">';
        break;
    case 2:
        echo '<form action="new-product-full-page-region.php" method="get">';
        break;

}  ?> 	   
<table width="200" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td  width="150"><select name="CatID" onChange="getState(this.value)">
      <option value="0">Select Category</option>
      <?php
do {  
?>
      <option value="<?php echo $row_RsCategories['CategoryID']?>"><?php echo $row_RsCategories['CategoryName']?></option>
      <?php
} while ($row_RsCategories = mysql_fetch_assoc($RsCategories));
  $rows = mysql_num_rows($RsCategories);
  if($rows > 0) {
      mysql_data_seek($RsCategories, 0);
  $row_RsCategories = mysql_fetch_assoc($RsCategories);
  }
?>
</select></td>
  </tr>
  <tr style="">
    <td ><div id="statediv"><select name="state" >
      <option>Select Category First</option>
    </select></div></td>
  </tr>
  <tr style="">
    <td ><div id="citydiv"><select name="city">
      <option>Select Country First</option>
    </select></div></td>
  </tr>
  <tr>
    <td><label>
      <input type="submit" name="submit" id="submit" value="Submit">
    </label></td>
  </tr>
  <tr>
    <td> </td>
  </tr>
</table>
</form>

 

Link to comment
https://forums.phpfreaks.com/topic/186511-switch-form-actions-not-working/
Share on other sites

<?php

$form_action = "DEFAULT LOCATION";

if (isset($_GET['CatID'])) {

switch ($CatID)

{

    case 1:

  $form_action = "new-product-full-page-citycountry.php";

        break;

    case 2:

    $form_action = "new-product-full-page-region.php";

        break;

echo '<form action="'.$form_action.'" method="get">

?>

 

<?php

$form_action = "DEFAULT LOCATION";

if (isset($_GET['CatID'])) {

switch ($CatID)

{

    case 1:

  $form_action = "new-product-full-page-citycountry.php";

        break;

    case 2:

    $form_action = "new-product-full-page-region.php";

        break;

echo '<form action="'.$form_action.'" method="get">

?>

 

i get an "Parse error: syntax error, unexpected $end in" pointing to the end of the code(this is an included file)

 

<?php
$form_action = "DEFAULT LOCATION";
if (isset($_GET['CatID'])) {
switch ($CatID)
{
    case 1:
   $form_action = "new-product-full-page-citycountry.php";
        break;
    case 2:
    $form_action = "new-product-full-page-region.php";
        break;
} 
}
echo '<form action="'.$form_action.'" method="get">
?>

Sorry 'bout that..

  • 2 weeks later...

for some

<?php
$form_action = "DEFAULT LOCATION";
if (isset($_GET['CatID'])) {
switch ($CatID)
{
    case 1:
   $form_action = "new-product-full-page-citycountry.php";
        break;
    case 2:
    $form_action = "new-product-full-page-region.php";
        break;
} 
}
echo '<form action="'.$form_action.'" method="get">
?>

Sorry 'bout that..

 

for some reason your example only gets the default location

 

i tried something different

but the action value is not passed on when you press submit the first time???

{code]

<?php

$CatID=$_GET['CatID'];

if (isset($CatID)) {

 

}

switch ($CatID)

{

    case 1:

$action='../region.php';

        break;

 

case 2:

$action='../city.php';

        break;

}

?>

<form action="<?php echo $action;?>" method="get">

[/code]

ok went client side as  i should have

<script type="text/javascript" language="javascript"> 

// form action URLS here, keyed to selected values
var action = Object();
     action['1'] = 'region.php';
    action['2'] = 'city.php';
    action['3'] = 'region.php';
   

function chkredir(oForm) {
     var oSelect = oForm.CatID; //get select
     oForm.action = action[oSelect[oSelect.selectedIndex].value]; //plug in selected value to action object
     return true;
} 

function checkform(oForm) {
     //validation routines here
     return chkredir(oForm);
}

</script>
<form onsubmit="return checkform(this)" method="GET">

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.