10 Replies - 8348 Views - Last Post: 26 June 2011 - 06:43 AM

#1 sweety_035   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-June 11

question:how can i call a php file after submit button(in form)

Posted 20 June 2011 - 08:57 AM

<script type="text/javascript">
function validform(){
var x=document.forms["form3"]["name"].value;
var y=document.forms["form3"]["f_name"].value;
var z=document.forms["form3"]["email"].value;
var atpos=z.indexOf("@");
var dotpos=z.lastIndexOf(".");
if(x==null || x=='')
{
 alert("your name is missing");

return false;
}
else if (y==null || y=='')
{
alert("your father name is missing");
return false;
}


else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=z.length)
  {
  alert("Not a valid e-mail address");
  return false;

  }

}

function submit1()
{
document.open('http://localhost/final/successfulllogin.php');

}
</script>

This post has been edited by Dormilich: 20 June 2011 - 10:52 AM
Reason for edit:: please use [code] /* your code source here */ [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: question:how can i call a php file after submit button(in form)

#2 Camerosaurus Rex   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 06-June 11

Re: question:how can i call a php file after submit button(in form)

Posted 20 June 2011 - 09:06 AM

This should help:

http://www.w3schools...hp/php_file.asp

EDIT: Misunderstood the question, OMIT.

This post has been edited by Camerosaurus Rex: 20 June 2011 - 09:07 AM

Was This Post Helpful? 0
  • +
  • -

#3 maniacalsounds   User is offline

  • D.I.C Regular
  • member icon

Reputation: 118
  • View blog
  • Posts: 474
  • Joined: 27-June 10

Re: question:how can i call a php file after submit button(in form)

Posted 20 June 2011 - 09:21 AM

A PHP file is automatically called after submit via the action attribute.

Example:
<form name="name= action="PHPFILE.php" method="POST">


This is always true, unless you have an onsubmit event handler to do javascript. Even if this is true, the PHP file is still called after the Javascript. Hope this helped!

This post has been edited by maniacalsounds: 20 June 2011 - 09:22 AM

Was This Post Helpful? 1
  • +
  • -

#4 youngone   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 12-June 11

Re: question:how can i call a php file after submit button(in form)

Posted 20 June 2011 - 09:26 AM

i'm not sure if i understood what you actually need. my guess is that you've got a form with some fields and you want to javascript-validate it before posting it. it's usually done by the following code:
<form method="post" action="yourphpfile.php>
...
<input type="submit" value="submit" onclick="yourvalidation(); return false;" />


Was This Post Helpful? 0
  • +
  • -

#5 maniacalsounds   User is offline

  • D.I.C Regular
  • member icon

Reputation: 118
  • View blog
  • Posts: 474
  • Joined: 27-June 10

Re: question:how can i call a php file after submit button(in form)

Posted 20 June 2011 - 09:30 AM

I agree with youngone, but you can also do it via onsubmit. This is used if you want to validate all of the fields at once (normally), because you can catch minute errors before the PHP script is run. Simply have a javascript function return false; if you don't like the input, and don't want the PHP script to run.
Was This Post Helpful? 0
  • +
  • -

#6 Ace26   User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 186
  • Joined: 10-August 08

Re: question:how can i call a php file after submit button(in form)

Posted 20 June 2011 - 09:41 AM

First of all, for future purposes, it will help a lot if you enclose you code in code tags.

To your question, do you intend to post form input to the server after validation? If yes then you should first of all make sure your form tag's action attribute(in your html page) has been set to the desired PHP page like so:

<form method = "post" action = "somePHPPage.php">
 <!-- you form elements for input go here -->
</form>



With that out of the way, attach a function (an event handler) to the onsubmit event of your form in your javascript code that will either send true or false to this event depending on the validation out come. If true is returned, the form will submit all the it's input values to the PHP page stated in the "action" attribute of your form, while a false means the submission is prevented.

EDIT: maniacalsounds beat me to it!

This post has been edited by Ace26: 20 June 2011 - 09:44 AM

Was This Post Helpful? 1
  • +
  • -

#7 sweety_035   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-June 11

Re: question:how can i call a php file after submit button(in form)

Posted 25 June 2011 - 10:34 AM

Thank you all for giving me your previous sugessions its really help full to me.once again thankx to all

This post has been edited by JackOfAllTrades: 26 June 2011 - 06:41 AM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#8 sweety_035   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-June 11

Re: question:how can i call a php file after submit button(in form)

Posted 25 June 2011 - 10:40 AM

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
function value()

{
invalid="";
nic;
	var a=document.form3.cnic.value;
	var b=document.form3.cnic1.value;
	var c=document.form3.cnic2.value;
	if(a=='' || a==invalid || b=='' || b==invalid || c=='' || c==invalid)
	{
	  alert("plz fill it");
	  return false;
	
	}
	alert(a+"-"+b+"-"+c);
	nic=a+"-"+b+"-"+c;
	
	return false;
	
	
	
}
</script>

<body>
<form  name="form3" onsubmit="value()">
<table>
<tr>
							<td><label>CNIC:</label></td>
							<td><input type="text" name="cnic" value="" onkeypress="return numberonly(event)"style="width:40px;" maxlength="5"/>-<input type="text" value="" name="cnic1" onkeypress="return numberonly(event)" style="width:100px;" maxlength="7" />-<input type="text" name=	
							"cnic2" value="" onkeypress="return numberonly(event)" style="width:30px;" maxlength="1" /></td>
							</tr> 
                            <tr>
                            <td><input type="submit" value="button"/></td>
                            </tr>
                            </table>

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



This is a form.This form has three text fields and i want to save these value in DATA BASE now tell me how can i put these values in post array??????????

This post has been edited by Martyr2: 25 June 2011 - 10:43 AM
Reason for edit:: Please use code tags in the future! Thanks! :)

Was This Post Helpful? 0
  • +
  • -

#9 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5291
  • View blog
  • Posts: 14,125
  • Joined: 18-April 07

Re: question:how can i call a php file after submit button(in form)

Posted 25 June 2011 - 10:48 AM

First, you need to add the attributes method="POST" and action="somescript.php" to your form tag. The result of the tag will look like...

<form method="POST" action="somescript.php" name="form3" onsubmit="value()">



What this is telling the form to do is that on submission of the form, send the form's data via POST to the somescript.php file (name this whatever you like, just make sure it points to a file you created). In that PHP file, those values from the form will automatically be available via the $_POST[] array. Then it is just a matter of reading them out.

To read the textbox you labeled with the name "cnic" you would access the value in the PHP script as $_POST["cnic"].

$cnic = $_POST["cnic"];
echo "The value submitted from the form for CNIC is: $cnic";



Hope that clarifies things. :)

This post has been edited by Martyr2: 25 June 2011 - 10:49 AM

Was This Post Helpful? 0
  • +
  • -

#10 sweety_035   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-June 11

Re: question:how can i call a php file after submit button(in form)

Posted 26 June 2011 - 04:24 AM

martyr2 you said that $_post['cnic'] but it just pick first text field value i want to pick 3 values togather

This post has been edited by sweety_035: 26 June 2011 - 04:25 AM

Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: question:how can i call a php file after submit button(in form)

Posted 26 June 2011 - 06:43 AM

Martyr2 is not HANDING you the code, sweety_035, he's EXPLAINING to you how it works so YOU can understand and write the code YOURSELF. This is not a code-writing service.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1