Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Redireccionar un submit a un ancla dentro de la misma pagina

Estas en el tema de Redireccionar un submit a un ancla dentro de la misma pagina en el foro de PHP en Foros del Web. Antes que todo un saludo. Bueno haber si puedo ser claro en lo que deseo hacer, sino diganme y buscare otra forma de explicarme: Estoy ...
  #1 (permalink)  
Antiguo 22/08/2013, 21:30
 
Fecha de Ingreso: mayo-2012
Ubicación: Distrito Federal
Mensajes: 49
Antigüedad: 11 años, 11 meses
Puntos: 9
Pregunta Redireccionar un submit a un ancla dentro de la misma pagina

Antes que todo un saludo.

Bueno haber si puedo ser claro en lo que deseo hacer, sino diganme y buscare otra forma de explicarme:

Estoy haciendo una pagina en php que funciona por medio de anclas (osea que cada enlace me redirige a una parte dentro de la misma pagina dejando la direccion de la siguiente manera index.php#perfiles )

Ahora bien, hay una seccion para el registro de usuarios por medio de un formulario el cual lo genero con dreamweaver, con el asistente de formulario de insercion de registros, en este ultimo hay un paso que me dice que despues de insertar los datos en la base de datos a donde deseo que me redirija.

Aqui es donde viene mi problematica ya que no quiero que me redirija a otra pagina sino a una seccion dentro de la misma, llamada registro_ok, intente poner la ruta de la siguiente manera:

index.php#registro_ok

pero no funciona ya que me manda solamente al index

Como podria poner la direccion para que una vez que oprima el boton submit me mande a esta seccion. O que solucion me recomiendan

Espero que me puedan ayudar, de antemano gracias.

NOTA: Aclaro que los datos si me los guarda en la bd, el problema como comento es la redireccionada
  #2 (permalink)  
Antiguo 22/08/2013, 21:43
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Redireccionar un submit a un ancla dentro de la misma pagina

¿Será posible que muestres el código responsable de eso o tenemos que adivinar?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 22/08/2013, 22:00
 
Fecha de Ingreso: mayo-2012
Ubicación: Distrito Federal
Mensajes: 49
Antigüedad: 11 años, 11 meses
Puntos: 9
Respuesta: Redireccionar un submit a un ancla dentro de la misma pagina

O es cierto una disculpa por eso, se me paso lo mas importante

Bueno, aqui esta el codigo php que me genera el dreamweaver

Código PHP:

<?php require_once('Connections/sistema.php'); ?>
<?php 
require_once('Connections/sistema.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

if (!
function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO clientes (num_cliente, nombre, ap_pat, ap_mat, direccion, telefono, email) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['num_cliente'], "int"),
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['ap_pat'], "text"),
                       
GetSQLValueString($_POST['ap_mat'], "text"),
                       
GetSQLValueString($_POST['direccion'], "text"),
                       
GetSQLValueString($_POST['telefono'], "int"),
                       
GetSQLValueString($_POST['email'], "text"));

  
mysql_select_db($database_sistema$sistema);
  
$Result1 mysql_query($insertSQL$sistema) or die(mysql_error());

  
$insertGoTo "index.php#registro_ok";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>

Por lo que veo en el codigo la parte que me redirige es esta:

$insertGoTo = "index.php#registro_ok";


pero pues no me funciona

Y este es el codigo del formulario:

Código:
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Num_cliente:</td>
      <td><input name="num_cliente" type="text" class="CampoDeTexto" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Nombre:</td>
      <td><input type="text" name="nombre" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Ap_pat:</td>
      <td><input type="text" name="ap_pat" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Ap_mat:</td>
      <td><input type="text" name="ap_mat" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Direccion:</td>
      <td><input type="text" name="direccion" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Telefono:</td>
      <td><input type="text" name="telefono" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Email:</td>
      <td><input type="text" name="email" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
  #4 (permalink)  
Antiguo 22/08/2013, 23:35
Avatar de j_silk_h  
Fecha de Ingreso: julio-2010
Mensajes: 54
Antigüedad: 13 años, 9 meses
Puntos: 6
Respuesta: Redireccionar un submit a un ancla dentro de la misma pagina

Modifica el action del form, coloca boca la dirección y el ancla y veras
__________________
!Si se puede imaginar se puede programar!
  #5 (permalink)  
Antiguo 23/08/2013, 00:48
 
Fecha de Ingreso: mayo-2012
Ubicación: Distrito Federal
Mensajes: 49
Antigüedad: 11 años, 11 meses
Puntos: 9
Respuesta: Redireccionar un submit a un ancla dentro de la misma pagina

Ya lo hice pero me sigue regresando al index, ademas al quitar el codigo php que esta en el action pues los datos ya no se guardan en la bd.

Lo que he pensado es que como esta parte del codigo es la que redirige:

$insertGoTo = "index.php#registro_ok";

Pues a lo mejor poniendo un codigo php se resolveria, pero la verdad es que he intentado poner varios, un ejemplo de los que he puesto es el que se usa normalmente para redireccionar en php: header('Location: index.php#registro_ok')

Pero da error, espero ir por buen camino, ojala me puedan ayudar

Gracias por tu pronta respuesta

Última edición por chuntaro18; 23/08/2013 a las 01:26
  #6 (permalink)  
Antiguo 24/08/2013, 08:43
Avatar de j_silk_h  
Fecha de Ingreso: julio-2010
Mensajes: 54
Antigüedad: 13 años, 9 meses
Puntos: 6
Respuesta: Redireccionar un submit a un ancla dentro de la misma pagina

aqui tu solucion

Código HTML:
<form method="post" name="form1" action="#registro_ok">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Num_cliente:</td>
      <td><input name="num_cliente" type="text" class="CampoDeTexto" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Nombre:</td>
      <td><input type="text" name="nombre" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Ap_pat:</td>
      <td><input type="text" name="ap_pat" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Ap_mat:</td>
      <td><input type="text" name="ap_mat" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Direccion:</td>
      <td><input type="text" name="direccion" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Telefono:</td>
      <td><input type="text" name="telefono" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Email:</td>
      <td><input type="text" name="email" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<div id="registro_ok" style="background:#F00;margin-top:600px;width:200px;height:"></div> 
le quite varias cosas, como esto

Código PHP:
  $insertGoTo "index.php#registro_ok"
  if (isset(
$_SERVER['QUERY_STRING'])) { 
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?"
    
$insertGoTo .= $_SERVER['QUERY_STRING']; 
  } 
  
header(sprintf("Location: %s"$insertGoTo)); 
ya que ya no hace falta
__________________
!Si se puede imaginar se puede programar!
  #7 (permalink)  
Antiguo 25/08/2013, 18:20
 
Fecha de Ingreso: mayo-2012
Ubicación: Distrito Federal
Mensajes: 49
Antigüedad: 11 años, 11 meses
Puntos: 9
Respuesta: Redireccionar un submit a un ancla dentro de la misma pagina

Muchas gracias por tu respuesta, me funciono a la perfeccion!!

GRACIAS

Etiquetas: formulario, redireccionar, registro, submit, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:27.