Login | Register | FAQ
Anonymous

form handled by function instead of page

+ Post a reply

8 posts Page 1 of 1


form handled by function instead of page

by jessedotnet » Mon Jun 25, 2012 3:51 pm

Is there a way to have a form handled by a php function within the same page as the form instead of being handled by a separate page. I have a simple mail form and when the mail is sent I would prefer an alert box to be displayed within the same page instead of having a new page loaded which displays "mail sent". Thanks for any suggestions
User avatar

jessedotnet

  • Posts: 20
  • Joined: Thu Jun 07, 2012 7:04 pm

Re: form handled by function instead of page

by chrisf1288 » Mon Jun 25, 2012 4:11 pm

<html>
<head>
<title>the-same-page.php</title>
</head>
<body>
<form action="the-same-page.php" method="get">
<input type="text" name="firstName" /><br />
<input type="text" name="lastName" /><br />
<input type="submit" />
</form>

First Name: <$php echo $_GET["firstName"]; ?><br />
Last Name: <$php echo $_GET["lastName"]; ?>
</body>
</html>
User avatar

chrisf1288

  • Posts: 128
  • Joined: Sun Jun 26, 2011 1:01 am

Re: form handled by function instead of page

by XainPro » Tue Jun 26, 2012 5:18 am

1 more option if you leave form action blank it will submit to the same page by default !
<form action="" method="get">
User avatar

XainPro

  • Posts: 3575
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: form handled by function instead of page

by jessedotnet » Tue Jun 26, 2012 10:17 pm

thank you chrisf1288 and XainPro for your help. I was able to get your suggestions to work but I had to change: <$php echo $_GET["firstName"]; to: <?php echo $_GET["firstName"];
unfortunately I am not able to use this method with my form because my form sends an email instead of generating html. It doesn't wait for form submission but instead sends a blank email. All the same I appreciate being able to familiarize myself with the "get" method.
User avatar

jessedotnet

  • Posts: 20
  • Joined: Thu Jun 07, 2012 7:04 pm

Re: form handled by function instead of page

by chrisf1288 » Tue Jun 26, 2012 10:47 pm

Oops, sorry about that syntax mistake.
User avatar

chrisf1288

  • Posts: 128
  • Joined: Sun Jun 26, 2011 1:01 am

Re: form handled by function instead of page

by XainPro » Wed Jun 27, 2012 5:33 am

Well i will Recommend you To Study And Learn AJAX Technique From AJAX you can send and receive data without page being refreshed.
User avatar

XainPro

  • Posts: 3575
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: form handled by function instead of page

by jessedotnet » Wed Jun 27, 2012 2:27 pm

Thank you for the tip.
User avatar

jessedotnet

  • Posts: 20
  • Joined: Thu Jun 07, 2012 7:04 pm

Re: form handled by function instead of page

by Flyinsky » Mon Jul 09, 2012 9:54 am

chrisf1288 wrote:<html>
<head>
<title>the-same-page.php</title>
</head>
<body>
<form action="the-same-page.php" method="get">
<input type="text" name="firstName" /><br />
<input type="text" name="lastName" /><br />
<input type="submit" />
</form>

First Name: <$php echo $_GET["firstName"]; ?><br />
Last Name: <$php echo $_GET["lastName"]; ?>
</body>
</html>


Thanks for the useful info.

--------------------
oil painting for sale
User avatar

Flyinsky

  • Posts: 1
  • Joined: Mon Jul 09, 2012 9:49 am


+ Post a reply

Page 1 of 1

?>