Jump to content

PHP form Help.


coolshrimp

Recommended Posts

i have a few things to sort out.is there an easy code to get form fields and assign them to variables rather then listing each one? see bellow

$Title = $_REQUEST['Title']$Name= $_REQUEST['Name']$Email= $_REQUEST['Email']$Comapny= $_REQUEST['Comapny']$Date= $_REQUEST['Date']is ther somthing like this (not a proper code I know)For each( field as string ){$(Field_Name) = $(Field_Value)}

also need to make this simpleri need to generate a table with the values sublitted to be emailed: bellow is what i use now. can we simplify it?

 $message = "<html><head><title>New Registration</title></head><body><table cellspacing="4" cellpadding="4" border="1" align="center">    <tr><td align="center">Title</td><td align="center">DOB</td><td align="center">Name</td><td align="center">Name_Passport</td><td align="center">Number_Passport</td><td align="center">Expire_Passport</td><td align="center">Country</td><td align="center">Country_Passport</td><td align="center">Visas</td><td align="center">Travel_Restrictions</td><td align="center">Address</td><td align="center">Phone</td><td align="center">Cell</td><td align="center">Email</td><td align="center">Skype</td><td align="center">Highest_Education</td><td align="center">Institution</td><td align="center">Degrees</td><td align="center">Certifications</td><td align="center">Why_Apply</td><td align="center">Community_Interests<td align="center">Special_Interests</td><td align="center">Share_Interests</td><td align="center">Languages</td><td align="center">Sponsor_Info</td><td align="center">Sponsor_Name</td><td align="center">Sponsor_Orginization</td><td align="center">Sponsor_Position</td><td align="center">Sponsor_Email</td><td align="center">Sponsor_Phone</td><td align="center">Sponsor_Country</td><td align="center">Employment_Organization</td><td align="center">Employment_Position</td><td align="center">Employment_Responsibilities</td><td align="center">Employment_Achievements</td><td align="center">Employment_Start</td><td align="center">Employment_Sector</td><td align="center">Employment_Organization_1</td><td align="center">Employment_Position_1</td><td align="center">Employment_Responsibilities_1</td><td align="center">Employment_Achievements_1</td><td align="center">Employment_Start_1</td><td align="center">Employment_End_1</td><td align="center">Employment_Organization_2</td><td align="center">Employment_Position_2</td><td align="center">Employment_Responsibilities_2</td><td align="center">Employment_Achievements_2</td><td align="center">Employment_Start_2</td><td align="center">Employment_End_2</td><td align="center">Date</td><td align="center">Time</td> 		  </tr>     <tr><td align="center">" . strip_tags($_REQUEST['Title']) . "</td><td align="center">" . strip_tags($_REQUEST['DOB']) . "</td><td align="center">" . strip_tags($_REQUEST['Name']) . "</td><td align="center">" . strip_tags($_REQUEST['Name_Passport']) . "</td><td align="center">" . strip_tags($_REQUEST['Number_Passport']) . "</td><td align="center">" . strip_tags($_REQUEST['Expire_Passport']) . "</td><td align="center">" . strip_tags($_REQUEST['Country']) . "</td><td align="center">" . strip_tags($_REQUEST['Country_Passport']) . "</td><td align="center">" . strip_tags($_REQUEST['Visas']) . "</td><td align="center">" . strip_tags($_REQUEST['Travel_Restrictions']) . "</td><td align="center">" . strip_tags($_REQUEST['Address']) . "</td><td align="center">" . strip_tags($_REQUEST['Phone']) . "</td><td align="center">" . strip_tags($_REQUEST['Cell']) . "</td><td align="center">" . strip_tags($_REQUEST['Email']) . "</td><td align="center">" . strip_tags($_REQUEST['Skype']) . "</td><td align="center">" . strip_tags($_REQUEST['Highest_Education']) . "</td><td align="center">" . strip_tags($_REQUEST['Institution']) . "</td><td align="center">" . strip_tags($_REQUEST['Degrees']) . "</td><td align="center">" . strip_tags($_REQUEST['Certifications']) . "</td><td align="center">" . strip_tags($_REQUEST['Why_Apply']) . "</td><td align="center">" . strip_tags($_REQUEST['Community_Interests']) . "</td><td align="center">" . strip_tags($_REQUEST['Special_Interests']) . "</td><td align="center">" . strip_tags($_REQUEST['Share_Interests']) . "</td><td align="center">" . strip_tags($_REQUEST['Languages']) . "</td><td align="center">" . strip_tags($_REQUEST['Sponsor_Info']) . "</td><td align="center">" . strip_tags($_REQUEST['Sponsor_Name']) . "</td><td align="center">" . strip_tags($_REQUEST['Sponsor_Orginization']) . "</td><td align="center">" . strip_tags($_REQUEST['Sponsor_Position']) . "</td><td align="center">" . strip_tags($_REQUEST['Sponsor_Email']) . "</td><td align="center">" . strip_tags($_REQUEST['Sponsor_Phone']) . "</td><td align="center">" . strip_tags($_REQUEST['Sponsor_Country']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Organization']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Position']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Responsibilities']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Achievements']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Start']) . "</td><td align="center">" . $Sector . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Organization_1']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Position_1']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Responsibilities_1']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Achievements_1']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Start_1']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_End_1']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Organization_2']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Position_2']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Responsibilities_2']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Achievements_2']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_Start_2']) . "</td><td align="center">" . strip_tags($_REQUEST['Employment_End_2']) . "</td><td align="center">" . date('Y-m-d') . "</td><td align="center">" . date("g:i A.", time()) . "</td>		  </tr>  </table></body></html>";

also can i generate this exact array with simpler code?

$row = array(       "Title" => $_REQUEST['Title']    , "DOB" => $_REQUEST['DOB']    , "Name" => $_REQUEST['Name']	    , "Name_Passport" => $_REQUEST['Name_Passport']    , "Number_Passport" => $_REQUEST['Number_Passport']	    , "Expire_Passport" => $_REQUEST['Expire_Passport']    , "Country" => $_REQUEST['Country']    , "Country_Passport" => $_REQUEST['Country_Passport']    , "Visas" => $_REQUEST['Visas']    , "Travel_Restrictions" => $_REQUEST['Travel_Restrictions']    , "Address" => $_REQUEST['Address']    , "Phone" => $_REQUEST['Phone']    , "Cell" => $_REQUEST['Cell']    , "Email" => $_REQUEST['Email']	    , "Skype" => $_REQUEST['Skype']    , "Highest_Education" => $_REQUEST['Highest_Education']    , "Institution" => $_REQUEST['Institution']    , "Degrees" => $_REQUEST['Degrees']	, "Certifications" => $_REQUEST['Certifications']	, "Why_Apply" => $_REQUEST['Why_Apply']	, "Community_Interests" => $_REQUEST['Community_Interests']	, "Special_Interests" => $_REQUEST['Special_Interests']	, "Special_Interests" => $_REQUEST['Share_Interests']	, "Languages" => $_REQUEST['Languages']	, "Sponsor_Info" => $_REQUEST['Sponsor_Info']	, "Sponsor_Name" => $_REQUEST['Sponsor_Name']	, "Sponsor_Orginization" => $_REQUEST['Sponsor_Orginization']	, "Sponsor_Position" => $_REQUEST['Sponsor_Position']	, "Sponsor_Email" => $_REQUEST['Sponsor_Email']	, "Sponsor_Phone" => $_REQUEST['Sponsor_Phone']	, "Sponsor_Country" => $_REQUEST['Sponsor_Country']	, "Employment_Organization" => $_REQUEST['Employment_Organization']	, "Employment_Position" => $_REQUEST['Employment_Position']	, "Employment_Responsibilities" => $_REQUEST['Employment_Responsibilities']	, "Employment_Achievements" => $_REQUEST['Employment_Achievements']	, "Employment_Start" => $_REQUEST['Employment_Start']	, "Employment_Sector" => $Sector			, "Employment_Organization_1" => $_REQUEST['Employment_Organization_1']	, "Employment_Position_1" => $_REQUEST['Employment_Position_1']	, "Employment_Responsibilities_1" => $_REQUEST['Employment_Responsibilities_1']	, "Employment_Achievements_1" => $_REQUEST['Employment_Achievements_1']	, "Employment_Start_1" => $_REQUEST['Employment_Start_1']	, "Employment_End_1" => $_REQUEST['Employment_End_1']		, "Employment_Organization_2" => $_REQUEST['Employment_Organization_2']	, "Employment_Position_2" => $_REQUEST['Employment_Position_2']	, "Employment_Responsibilities_2" => $_REQUEST['Employment_Responsibilities_2']	, "Employment_Achievements_2" => $_REQUEST['Employment_Achievements_2']	, "Employment_Start_2" => $_REQUEST['Employment_Start_2']			, "Employment_End_2" => $_REQUEST['Employment_End_2']	  	, "Date" => date('Y-m-d')	, "Time" => date("g:i A.", time())    );
Edited by coolshrimp
Link to comment
Share on other sites

ok so for my second box where i have "$message =" this would be the correct code?i tested and it seems the generate the table propperlly on a blank page.

 

but so now how can i set it to $message= so that i can sen it in an email?

<?php echo "<table cellspacing="4" cellpadding="4" border="1" align="center"><tr>";foreach ($_POST as $key => $value) {  echo "<td align="center">" . $key . "</td>";}echo "<td align="center">Date</td>";echo "<td align="center">Time</td>";echo "</tr><tr>";foreach ($_POST as $key => $value) {  echo "<td align="center">" . strip_tags($value) . "</td>";} echo "<td align="center">" . date('Y-m-d') . "</td>"; echo "<td align="center">" . date("g:i A.", time()) . "</td>"; echo "</tr>"; echo "</table>";   ?>
Edited by coolshrimp
Link to comment
Share on other sites

here is a full code im trying to get to work.im using EOF (end of file) so i dont have to escape quotations.im guessing for the date and time i have to assign to a variable and then add the variable to the message instead? ($date = date('Y-m-d'))

<?php  $to = "Me@email.com"; $name = $_REQUEST['Name']; $subject = "Email Form";  $from = $_REQUEST['Email']; $headers = 'MIME-Version: 1.0' . "rn" . 'Content-type: text/html; charset=iso-8859-1' . "rn" . "From:" . $name . " <" . $from . ">" . "rn" . "Reply-To:" . $from . "rn";$message = <<<EOF<html><head><title>Email</title></head><body><table cellspacing="4" cellpadding="4" border="1" align="center"><tr>foreach ($_POST as $key => $value) { <td align="center">" . $key . "</td>} <td align="center">Date</td><td align="center">Time</td></tr><tr>foreach ($_POST as $key => $value) { <td align="center">" . strip_tags($value) . "</td>}<td align="center">" . date('Y-m-d') . "</td><td align="center">" . date("g:i A.", time()) . "</td></tr></table></body></html>EOF;echo $message;  if (mail($to,$subject,$message,$headers)) {   echo "Email sent";  } else {   echo "Failed To Send Email";  }  }   ?>
Edited by coolshrimp
Link to comment
Share on other sites

ok using this it got it to work is there anything wrong with doing it like this and is there a simpler way?

<?php  $to = "me@email.com"; $name = $_REQUEST['Name']; $subject = "Email Form";  $from = $_REQUEST['Email']; $headers = 'MIME-Version: 1.0' . "rn" . 'Content-type: text/html; charset=iso-8859-1' . "rn" . "From:" . $name . " <" . $from . ">" . "rn" . "Reply-To:" . $from . "rn";$message .= "<table cellspacing="4" cellpadding="4" border="1" align="center"><tr>";foreach ($_POST as $key => $value) {  $message .=  "<td align="center">" . $key . "</td>";}$message .=  "<td align="center">Date</td>";$message .=  "<td align="center">Time</td>";$message .=  "</tr><tr>";foreach ($_POST as $key => $value) {  $message .=  "<td align="center">" . strip_tags($value) . "</td>";} $message .=  "<td align="center">" . date('Y-m-d') . "</td>"; $message .=  "<td align="center">" . date("g:i A.", time()) . "</td>"; $message .=  "</tr>"; $message .=  "</table>";    if (mail($to,$subject,$message,$headers)) {   echo  "Email sent";  } else {   echo  "Failed To Send Email";  }    ?>
Link to comment
Share on other sites

is it ok to do it this way? (EOF)so i dont have to escape quotes..

<?php  $to = "me@email.com"; $name = $_REQUEST['First_Name']; $subject = "Email Form";  $from = $_REQUEST['Email']; $headers = 'MIME-Version: 1.0' . "rn" . 'Content-type: text/html; charset=iso-8859-1' . "rn" . "From:" . $name . " <" . $from . ">" . "rn" . "Reply-To:" . $from . "rn";//********  Generate Table and assign to $message ************************//$message = <<<EOF<table cellspacing="4" cellpadding="4" border="1" align="center"><tr> EOF;foreach ($_POST as $key => $value) {  $message .=  "<td align="center">" . $key . "</td>";}$message .= <<<EOF<td align="center">Date</td><td align="center">Time</td></tr><tr>EOF;foreach ($_POST as $key => $value) {  $message .=  "<td align="center">" . strip_tags($value) . "</td>";}$message .= <<<EOF<td align="center">EOF;$message .= date('Y-m-d');$message .= <<<EOF</td><td align="center">EOF;$message .= date("g:i A.", time());$message .= <<<EOF</td></tr></table> EOF; if (mail($to,$subject,$message,$headers)) {   echo  "Email sent";  }   else   {   echo  "Failed To Send Email";}    ?>
Link to comment
Share on other sites

You can also just use the other type of quotes:

$message .= '<td align="center">';

$row = $_POST;$row['Date'] = date('Y-m-d');$row['Time'] = date("g:i A.", time());

I don't see what you gain by using another variable instead of just adding those values directly to $_POST.
Link to comment
Share on other sites

yes i got it this way now. so the php generates the date and time and adds it to the $_post array

$_POST['Date'] = date('Y-m-d');$_POST['Time'] = date("g:i A.", time());$row = $_POST;

thanks for your guys help i got the whole thing working properly now.i dont know PHP very well but i know enfough to get things working and somewhat how they work.

Link to comment
Share on other sites

  • 2 weeks later...

I didnt know where to post,so ill post here.I have a little problem figuring out this..

http://prntscr.com/59ao21 When i click serie A or premier league,i want in fields below to list just teams from those leagues http://prntscr.com/59aosj and not all teams from my database.Can someone help me ??? I use codeigniter and everything else is working just fine

<p>Избери лига: <select name="ligi">
<option value=""> Одбери </option>
<option value=""> Serie A </option>
<option value=""> Premier League </option>
</select></p>
</form>
<form action="" method="get">
<p>Тим 1: <select name="tim1">
<?php foreach($timovi as $team){?>
<option value="<?php echo $team['id'];?>" <?php if(@$_GET['tim1']==$team['id']){
echo 'selected="selected"';
};?>><?php echo $team['name'];?></option>
<?php }?>
</select></p>
Link to comment
Share on other sites

You need to use Javascript to add an event handler to the select box, which would get the value that was selected and send an ajax request to the server to get the list of records for that value, then fill in the other select list with those options.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...