Jump to content

PHP form


aus31

Recommended Posts

A form is posted by HTML, and received by PHP.

You do so by using the action function to your form tag.

<form method="POST" action="your_PHP_script.php">

 

When you press the submit button on your form there will be created variables that a php script could fetch.

This you could be done by using this code:

	$your_php_variable = !empty($_POST ['name_of_form_tag']) ? $_POST['name_of_form_tag'] : '';

This code also makes sure the variable is not empty, witch could produce an error with some databases.

 

now the form input is in a php variable that you could use to whatever you want. Who that is able to see the data you control with your php. 

 

And as pikachu says, post some code and describe your errors.

 

Link to comment
https://forums.phpfreaks.com/topic/223803-php-form/#findComment-1156800
Share on other sites

You can see the form code below. What i don't know is how to write a code that will send all the data from the form below to a certain page of my website, where the data can then be viewed. Am i making any sense?How can this be done?

 

<form name="contactform" method="post" action="http://domain.com/send.php"><table width="790" border="0" cellspacing="2" cellpadding="0">

<tr>

<td width="16%" align="left" valign="middle" class="bodytext"><p class="content-subeading style1 style1">Full name </td>

<td width="28%"><input  type="text" name="name"  class="one" maxlength="50" size="30"> </td>

<td width="56%" rowspan="5"> </td>

</tr>

<tr>

<td height="49" class="bodytext"><p class="content-subeading style2">Company</td>

<td><input  type="text" name="company"  class="one" maxlength="50" size="30"> </td>

</tr>

<tr>

<td class="bodytext"><p class="content-subeading style2">Email</td>

<td><input  type="text" name="email"  class="one" maxlength="50" size="30"> </td>

</tr>

<tr>

<td height="38" class="bodytext"> </td>

<td align="left" valign="bottom"> 

  <textarea name="comment" cols="45" rows="10" id="comment" class="two"></textarea></td>

</tr>

<tr>

  <td class="bodytext"> </td>

  <td align="left" valign="top"><input type="submit" name="Submit2" value="Send" /> </td>

  </tr>

</table></form>

Link to comment
https://forums.phpfreaks.com/topic/223803-php-form/#findComment-1156804
Share on other sites

1. page 1 is the form page

2. page 2 is 'send.php', it gathers the data from the form variables (via $_POST)and stores them in a database table

3. page 3 is the admin login page

4. page 4 (A) restricts access to the admin; (B) retreives the data from the database and displays it for the admin to view

Link to comment
https://forums.phpfreaks.com/topic/223803-php-form/#findComment-1156814
Share on other sites

This form send all its data to http://domain.com/send.php.

You need to change this to the page name that is supposed to handle the data.

 

On this page you need to collect all the data and save them to a database.

 

Take a look on this link to learn the basics on how to handle form data with php.

http://www.tizag.com/phpT/forms.php

Link to comment
https://forums.phpfreaks.com/topic/223803-php-form/#findComment-1156818
Share on other sites

This form send all its data to http://domain.com/send.php.

You need to change this to the page name that is supposed to handle the data.

 

On this page you need to collect all the data and save them to a database.

 

Take a look on this link to learn the basics on how to handle form data with php.

http://www.tizag.com/phpT/forms.php

 

You can see the the php code that send the form data below. The code send the data to an email address...what do i need to change in the code so that the data will be sent to a certain page on my website?

 

<?php

if ($_POST["email"]<>'') {

$ToEmail = '[email protected]';

$EmailSubject = 'Contact us ';

$mailheader = "From: ".$_POST["email"]."\r\n";

$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";

$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

$MESSAGE_BODY = "Full name ".$_POST["name"]."<br>";

$MESSAGE_BODY .= "Email address: ".nl2br($_POST["email"])."<br>";

        $MESSAGE_BODY .= "Company: ".$_POST["company"]."<br>";

$MESSAGE_BODY .= "Subject: ".$_POST["subject"]."<br>";

        $MESSAGE_BODY .= "Message: ".$_POST["message"]."<br>";

       

     

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

?>

Thank you for contacting us. Your message was sent.

<?php

} else {

?> <form name="contactform" method="post" action="http://www.domain.com/send.php"><table width="790" border="0" cellspacing="2" cellpadding="0">

<tr>

<td width="16%" align="left" valign="middle" class="bodytext"><p class="content-subeading style1 style1">Full name </td>

<td width="28%"><input  type="text" name="name"  class="one" maxlength="50" size="30"> </td>

<td width="56%" rowspan="5"> </td>

</tr>

<tr>

<td height="49" class="bodytext"><p class="content-subeading style2">Company</td>

<td><input  type="text" name="company"  class="one" maxlength="50" size="30"> </td>

</tr>

<tr>

<td class="bodytext"><p class="content-subeading style2">Email</td>

<td><input  type="text" name="email"  class="one" maxlength="50" size="30"> </td>

</tr>

<tr>

<td height="38" class="bodytext"> </td>

<td align="left" valign="bottom"> 

  <textarea name="comment" cols="45" rows="10" id="comment" class="two"></textarea></td>

</tr>

<tr>

  <td class="bodytext"> </td>

  <td align="left" valign="top"><input type="submit" name="Submit2" value="Send" /> </td>

  </tr>

</table></form>

<?php

};

?>

Link to comment
https://forums.phpfreaks.com/topic/223803-php-form/#findComment-1156821
Share on other sites

Then you need to store your data to a database.

You could store it directly into your web page using fwrite, but i guess thats not what you want to do.

 

You want to post the data to a web page, what type of page is this? Some kind of commenting function?

 

If you got no clew on how to do this i recommend some more reading for you.

http://www.tizag.com/phpT/

http://www.w3schools.com/php/default.asp

 

Focus on form handling and database connections.

 

You could hope that someone would write you your code, but i think you have to wait for some time.

Read a bit, write some code and then ask for help when you have some errors.

Link to comment
https://forums.phpfreaks.com/topic/223803-php-form/#findComment-1156843
Share on other sites

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.