Jump to content


Photo

Formulario Php+ajax


  • Faça o login para participar
11 replies to this topic

#1 automouse

automouse

    Turista

  • Usuários
  • 37 posts
  • Sexo:Não informado

Posted 21/05/2006, 16:10

Olá usuários do WM online, eu fiz um script em php o qual ele pega o radiobutton escolhido e exibe na tela.
ficou assim:
<div id="texto">
<form name="form1" method="post" action="exp.php?acao=take">


<input name="radio" type="radio" checked="checked" value="escolha 1" />
	escolher 1?</label>

<input name="radio" type="radio" value="escolha 2" />
	escolher 2?</label>

<input name="radio" type="radio" value="escolha 3" />
	escolher 3?</label>

<input name="radio" type="radio" value="escolha 4" />
	escolher 4?</label>
<input type='submit' value=' submeter '>


	</form></div>
	</body>
	</html>

<?php
  if(@$_GET['acao']=="take"){
	echo $_POST['radio'];
  }
  ?>

ok, funcionou perfeitamente, mas como colocar ajax nisso pra atualizar dados sem atualizar a página?
tentei assim:
<html>
<head>
<title>document</title>
</head>
<body>
<script language="JavaScript">
<!--
var xmlhttp;

function verificar(form) {
	var body = "";

		if (window.XMLHttpRequest) {
				xmlhttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			alert("Seu navegador não suporta XMLHttpRequest.");
				return;
		}

	xmlhttp.open("GET", "index.php?acao=take", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	xmlhttp.onreadystatechange = processReqChange;
	xmlhttp.send(null);
	
}

function processReqChange() {
	if(xmlhttp.readyState == 1){
	  document.getElementById("texto").innerHTML = "Carregando...!";
	  }
	if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				document.getElementById("texto").innerHTML = xmlhttp.responseText;
				} else {
					alert("Problemas ao carregar o arquivo.");
				}
	}
}
//-->
</script>



<div id="texto">
<form name="form1" method="post">


<input name="radio" type="radio" checked="checked" value="escolha 1" />
	escolher 1?</label>

<input name="radio" type="radio" value="escolha 2" />
	escolher 2?</label>

<input name="radio" type="radio" value="escolha 3" />
	escolher 3?</label>

<input name="radio" type="radio" value="escolha 4" />
	escolher 4?</label>

	<input type="button" onclick="verificar(this.form)" value=" Votar ">
	
	</form></div>
	</body>
	</html>

<?php
  if(@$_GET['acao']=="take"){
	echo $_POST['radio'];
  }
  ?>

Mas como podem ver apareceu o seguinte erro:

Notice: Undefined index: radio in c:\arquivos de programas\easyphp1-7\www\tests\index.php on line 73


onde eu tenho que arrumar pro ajax funcionar?

Desde já obrigado.

Edição feita por: automouse, 21/05/2006, 21:16.


#2 Renan Gonçalves

Renan Gonçalves

    Web Developer

  • Usuários
  • 771 posts
  • Sexo:Masculino
  • Localidade:São Paulo, SP
  • Interesses:Programar PHP, Java (e JSP), Javascript (com Ajax, claro), Ruby (on Rails) !

Posted 21/05/2006, 16:23

Então, aqui é o Web Master e não IMasters.

E tipo, invez de você fazer a requisição pelo método GET faça por POST e envie junto as informações do formulário.
Ou seja, faça:
ajax.open("POST", "pagina.php", true);
...
ajax.send(dados + '&acao=fake')
Onde dados será os dados do formulário.

http://forum.wmonlin...howtopic=146865


[]'s

Renan Gonçalves
renan.saddam@gmail.com
(WebSite / Gmail / orkut / Windows Live! Messenger
)

"Aquele que se define se limita."


#3 automouse

automouse

    Turista

  • Usuários
  • 37 posts
  • Sexo:Não informado

Posted 21/05/2006, 21:25

e aí Renan já troquei pra WM, foi mal...

Me explica uma coisa, tendo o formulario do meu 1º post neste tópico como ficaria o dados nessa parte:

ajax.send(dados + '&acao=fake')

?

Não entendi quando você falou pra mandar também informações sobre o formulario :unsure:

Desde já obrigado

Edição feita por: automouse, 21/05/2006, 21:26.


#4 Renan Gonçalves

Renan Gonçalves

    Web Developer

  • Usuários
  • 771 posts
  • Sexo:Masculino
  • Localidade:São Paulo, SP
  • Interesses:Programar PHP, Java (e JSP), Javascript (com Ajax, claro), Ruby (on Rails) !

Posted 21/05/2006, 22:02

Seguinte amigo.

O dados seria exatamente a informação do formulário.
Se você quer fazer que mande a opção selecionada no RadioButton então terá que fazer uma função que pegue tal valor e envie para o Ajax, algo do tipo:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>New document</title>
<script language="JavaScript">
function enviaForm()
{
	var objeto = document.form1.escolha;
	var escolha = null;

	for (var i = 0; i < objeto.length; i++)
	{
		if (objeto[i].checked)
			escolha = objeto[i].value;
	}

	// Chama a função do Ajax e passa:
	var dados = 'opcaoEscolhida=' + escolha;

	return false;
}
</script>
</head>
<body>

<div id="texto">
<form name="form1" method="post" onSubmit='return enviaForm()'>


<input name="escolha" type="radio" checked="checked" value="escolha 1" />escolher 1?
<input name="escolha" type="radio" value="escolha 2" />escolher 2?
<input name="escolha" type="radio" value="escolha 3" />escolher 3?
<input name="escolha" type="radio" value="escolha 4" />escolher 4?

<input type='submit' value=' submeter '>
</form>

</body>
</html>
Ai, ali dentro da funçao enviaForm você chama a função do Ajax, ou então faz ali mesmo a requisição.

Leia: http://forum.wmonlin...howtopic=146865


[]'s

Renan Gonçalves
renan.saddam@gmail.com
(WebSite / Gmail / orkut / Windows Live! Messenger
)

"Aquele que se define se limita."


#5 automouse

automouse

    Turista

  • Usuários
  • 37 posts
  • Sexo:Não informado

Posted 28/05/2006, 10:35

Ei Renan funcionou!!
Valeu mesmo cara!!

Mas me diga uma coisa se eu clicar duas vezes vai aparecendo assim por exemplo:

opcao escolhida: 2
opcao escolhida: 1


como faço pra apagar o resultado anterior?
tentei um document.texto.value="";
mas como o form dos radiobuttons estão dentro da div texto apaga tudo! e se eu colocar a div em cima ou embaixo do form não funciona =(

por exemplo se meu form estiver assim:
<form name="form1" method="post" onSubmit='return verificar(this.form)'>

<h2>Teste utilizando método POST</h2>
 <input name="escolha" type="radio" checked="checked" value="escolha 1" />
	escolher 1?</label>

 <input name="escolha" type="radio" value="escolha 2" />
	escolher 2?</label>

 <input name="escolha" type="radio" value="escolha 3" />
	escolher 3?</label>

 <input name="escolha" type="radio" value="escolha 4" />
	escolher 4?</label>

	<input type='submit' value=' submeter '>

	[b]<div id="texto"></div>[/b]

desde já agradeço (y)

#6 RonsisM

RonsisM

    Super Veterano

  • Usuários
  • 15724 posts
  • Sexo:Masculino
  • Localidade:Plovdiv

Posted 16/09/2017, 08:31

Zithromax Ten Days cheap cialis Buy Zithromax In The Uk Amoxicillin 1000mg Pentoxifylline To Buy Online Pharmacy 24h cheap cialis Generique Utrogestan
Cheap Unisom online pharmacy Tadalis Sx Online Kaufen
Generic Keflex Maxifort Zimax Sildenafil 50 Mg
Amoxil 2 <a href=http://cialtobuy.com>cialis online</a> Discount Fedex Shipping Bentyl Website Internet Overseas
Viagra Over The Counter In Hong Kong buy cialis Vardenafil Generico buy cheap accutane online no prescription Canadian Pharmasuticals Viagra generic cialis Cialis In Der Apotheke Kaufen

#7 RonsisM

RonsisM

    Super Veterano

  • Usuários
  • 15724 posts
  • Sexo:Masculino
  • Localidade:Plovdiv

Posted 03/10/2017, 10:57

Otc Zithromax Precio Cialis Tabletas Differenze Viagra Cialis Levitra viagra Fairness
Achat De Cialis Sur Internet isotretinoin 10mg no prior script Brand Viagra Shipped Overnight From Usa buy viagra online Toncils Infection Amoxicillin Daily Cialis Without Prescription On Line Bentyl Real France Pharmacy Shipped Ups

#8 HaroNism

HaroNism

    Super Veterano

  • Usuários
  • 15385 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 03/10/2017, 20:42

Viagraprofessionalwithoutaprescription Where To Purchase Stendra best price for levitra 20mg Venta Cialis En Andorra
Efecto Del Viagra Con Alcohol Cialis Mezza Pastiglia Cialis Tablet brand levitra online Amoxicillin For Sinus Infection Zithromax Urine Smell
Sky Pharmacy Online vardenafil hcl 20mg tab Will Cephalexin Kill Good Bacteria
Stendra Avanafil Cost Propecia With Birth Control Pills Avodart viagra online Kamagra Francia Propecia Trama
Fluoxetine Cash Delivery. Fluoxetine Without Perscription Legally Cialis 5 Mg Generico Online viagra Keflex Shelf Life
Viagra Kaufen Per Uberweisung viagra Cialis Kaufen Deutsch Viagra Und Andere Potenzmittel Albuterol Without Script
Vente Cialis Prix Cialis Testimonios online pharmacy Dapoxetine Price
Se Vende Viagra Madrid buy viagra online Bebe Avec Clomid Is Cephalexin Used For Bladder Infections
Tadalis Sx Soft Like Prozac For Sale Online viagra online Fluconozole Dogs On Line Doxycycline
Order Brand Name Viagra Online online pharmacy Viagra O Cosa Compra Kamagra En Espana Fluoxetine 40mg Eating Disorder Where To Order
Pvp Cialis 20 Mg Levitra Ohne Zollprobleme viagra prescription Cialis Wirkung Nebenwirkung Cialis Viagra Combo Pack Support

#9 Miguceamma

Miguceamma

    MiguPenjisse

  • Usuários
  • 13201 posts

Posted 04/10/2017, 00:15

Ward Color Viagra Wirkung Bei Gesunden Viagra Contre Le Decalage Horaire viagra Byetta And Gastric Dumping Zithromax And Cialis Mail Order Free Shipping Provera Medroxine Direct In Internet

#10 HaroNism

HaroNism

    Super Veterano

  • Usuários
  • 15385 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 04/10/2017, 09:23

Levaquin And Zithromax viagra prescription Acheter Du Viagra Where To Buy Effexor Over The Counter Cheap Kamagra Viagra

#11 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 05/10/2017, 03:26

Buy Cheap Viagra Online wheretobuylevitrapills Cialis Und Ssri Propecia Effets Secondaires Spertomax
Propecia Langzeitfolgen brand levitra online Ordonnance Tadalis Sx Soft Singapour Amoxicillin Clav K
Buy Cheap Accutane Online vivanza 20mg Buy Azithromycin No Prescription Como Funciona El Cialis
Prix Levitra 20mg France No Rx Mirtazapine 30 Mg Antidepressants viagra online Propecia Instalar
Levitra Consult generic viagra Amoxicillin For Sinus Infection Isotretinoin 10mg where to buy Viagra Wirkung Bei Frau
Buy Levitra Ireland Zithromax Allergy Rx 4 Amoxicillin viagra online Cephalexin Erowid Viagra Mode Emploi Propecia Cancer De Prostata
Bacterial Infection Treated With Keflex Pain Pills Online viagra Buy Cheap Strattera Online Amoxicillin With Food Or Without Food

#12 RonsisM

RonsisM

    Super Veterano

  • Usuários
  • 15724 posts
  • Sexo:Masculino
  • Localidade:Plovdiv

Posted 29/10/2017, 17:15

Vivanza 20mg Cialis Achat Espagne viagra Levitra Blutverdunner Easiest Way To Get An Ed Perscription
Amoxicillin Missed Period viagra Doxycycline Claravis Carmarthenshire Online Pharmacy Finax Propecia Spain Cialis Levitra
Dizziness As Side Effect Of Amoxicillin Hydrochlorothiazide Next Day Delivery Daily Cialis Without A Prescription viagra Cialis Se Usa
Cialis GСÐРСÐвÐâСÐСÑРÐÐÂnstig Kaufen Celecoxib Online generic viagra Propecia Cruz Verde Onlinephatmacies




0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq