Jump to content

Basic PHP assignment


TrillionBuks

Recommended Posts

Good afternoon everyone. I am new to PHP and as a consequence new to this site. I am applying for an internship with a web company and they gave me a sample assignment to complete. They know I do not have any experience with PHP and said they want me to be resourceful and seek out a way of completing the assignment. In addition to the assignment I would like to practice at home in a windows environment. Do you have any recommendations for a free download?

 

The following are the parameters of the assignment I was given:

 

Develop a form that gathers and emails all the info upon submitting it.

 

Form structure:

 

first_name, last_name, email, phone

 

all fields are required

 

validate the email and phone structure

 

Any information is appreciated. Thank you in advance!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/
Share on other sites

The assignment is a very basic one. Easy enough.

 

I am confident that by using this forum's search bar and the one on http://www.google.com, you will find all the information that you need. If you get stuck, come back and ask a question about what's not working.

 

I code in Dreamweaver (not free anymore?) or Notepad (free). A lot of people say that Eclipse (free) with the PHP plugin is teh best PHP editor that they've used.

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488756
Share on other sites

to setup a quick php server, use: http://sourceforge.net/projects/xampp/

 

to create a form, and to process the results: http://www.tizag.com/phpT/forms.php

 

for sending the info in an email: http://us.php.net/mail

 

here is an example: http://php.about.com/od/phpapplications/ss/form_mail.htm

 

you will first create the html form...

 

<form>
<input type="text" name="first_name">......

</form>

 

then you will use php to capture the results and then plug them into the mail function (php.net/mail) to send to wherever.

 

for validation, for email (<input type="text" name="email">):

 

if (document.forms[0].elements["email"].value == "") {
	window.alert("Please enter your email");
	return false;
}

validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	strEmail = document.forms[0].email.value;

  // search email text for regular exp matches
if (strEmail.search(validRegExp) == -1) 
{
	alert('A valid email address is required.\nPlease amend and retry');
	return false;
   } 

 

for phone validation:

http://www.developerfusion.co.uk/show/5630/

 

work on first creating the html form, then getting the results.

 

 

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488771
Share on other sites

Upon my initial research I see that PHP makes call to headers and executes the data contained on the page. Is that a correct understanding of the following snippet of code?

 

if (!isset($_REQUEST['email'])) {

    header( "Location: http://www.example.com/feedback.html" );  //verifies if variable has been defined, calls header with some sort of feedback

 

  }

  elseif (empty($email) || empty($message)) {

    header( "Location: http://www.example.com/error.html" ); //if either field is empty call the error.html header and execute instructions within

 

  }

  else {

    mail( "[email protected]", "Feedback Form Results",

      $message, "From: $email" );

    header( "Location: http://www.example.com/thankyou.html" ); //everything checks and execute confirmation from thankyou.html

 

If so, do I need to create dummy headers and instructions to have my code call from them? Do you think I can just make up pertinent names without creating the file to back up the call? How can I test my program in a windows environment? You mentioned notepad with a php plugin; Will that enable me to test my code for syntax errors and logical mistakes?

 

Thanks again!

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488777
Share on other sites

The header("Location: ...")s don't do anything but redirect the user to a new page. It validates what data the user has sent using an HTML form and depending on that data it gives an appropriate response. (For example, the first one "!isset($_REQUEST['email'])" checks to see if the user has given his/her email address (if the inverse of the value returned by isset($_REQUEST['email']) is true); if the user hasn't, simply take them back to the original form.

 

It sounds like you are from a C (or like) background; note that PHP does not have header files in the context you are using them; header() refers to the http:// header sent to the clients web browser.

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488781
Share on other sites

to setup a quick php server, use: http://sourceforge.net/projects/xampp/

 

to create a form, and to process the results: http://www.tizag.com/phpT/forms.php

 

for sending the info in an email: http://us.php.net/mail

 

here is an example: http://php.about.com/od/phpapplications/ss/form_mail.htm

 

you will first create the html form...

 

<form>
<input type="text" name="first_name">......

</form>

 

then you will use php to capture the results and then plug them into the mail function (php.net/mail) to send to wherever.

 

for validation, for email (<input type="text" name="email">):

 

if (document.forms[0].elements["email"].value == "") {
	window.alert("Please enter your email");
	return false;
}

validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	strEmail = document.forms[0].email.value;

   // search email text for regular exp matches
if (strEmail.search(validRegExp) == -1) 
{
	alert('A valid email address is required.\nPlease amend and retry');
	return false;
    } 

 

for phone validation:

http://www.developerfusion.co.uk/show/5630/

 

work on first creating the html form, then getting the results.

 

 

 

I appreciate all the information. A quick question about "validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;" I have never seen code like this before and was wondering if you can explain to me what is going on. I am assuming that it is checking to see if the email string contains valid characters followed by an '@' some more valid characters (a-z) then a period and finally a valid extension. Adain this my assumption and would appreciate a detailed breakdown of it for my knowledge.

 

Thanks again!

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488797
Share on other sites

to setup a quick php server, use: http://sourceforge.net/projects/xampp/

 

to create a form, and to process the results: http://www.tizag.com/phpT/forms.php

 

for sending the info in an email: http://us.php.net/mail

 

here is an example: http://php.about.com/od/phpapplications/ss/form_mail.htm

 

you will first create the html form...

 

<form>
<input type="text" name="first_name">......

</form>

 

then you will use php to capture the results and then plug them into the mail function (php.net/mail) to send to wherever.

 

for validation, for email (<input type="text" name="email">):

 

if (document.forms[0].elements["email"].value == "") {
	window.alert("Please enter your email");
	return false;
}

validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	strEmail = document.forms[0].email.value;

   // search email text for regular exp matches
if (strEmail.search(validRegExp) == -1) 
{
	alert('A valid email address is required.\nPlease amend and retry');
	return false;
    } 

 

for phone validation:

http://www.developerfusion.co.uk/show/5630/

 

work on first creating the html form, then getting the results.

 

 

 

I appreciate all the information. A quick question about "validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;" I have never seen code like this before and was wondering if you can explain to me what is going on. I am assuming that it is checking to see if the email string contains valid characters followed by an '@' some more valid characters (a-z) then a period and finally a valid extension. Adain this my assumption and would appreciate a detailed breakdown of it for my knowledge.

 

Thanks again!

 

can't really offer you a detailed breakdown of it, all i know is, it works, and its javascript. i won't lie, i copy and paste a lot of things that i use, which is something i use. but all you really need to know is this works, just name your input field like: <input type="text" name="email">, then you're good to go for validation the email field. all that /^[^@]+ is regular expression, its better you get to the html form first, then begin worrying about the validation. i would say you would validate last.

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488800
Share on other sites

It's not javascript, it's a regular expression (regex)... a very powerful search language. You can find more about it here

 

http://www.regular-expressions.info/

 

If you are going to be using regex on a regular basis, i highly recommend regexbuddy (the program advertised on that site)

 

Also, as a subnote.. i really like the php/mysql/apache installer here:

http://www.wampserver.com/en/

 

And I really like Serge Baranov's build of SciTE for a basic programming environment:

http://amip.tools-for.net/SciTE-CVS.exe

 

Oh, and what you asked... a breakdown of the regex

 

/ - begin regular expression

^ - start of string

followed by

[^@]+ - match any character that is not '@', 1 or more times

followed by

@ - match character '@'

followed by

[^@]+ - match any character that is not '@', 1 or more times

followed by

. - match any character that's not a linebreak... i believe this should be '\.' which is match '.'

followed by

[a-z]{2,} - match a through z, 2 or more times... i believe this should be [a-z.]{2,} which will match a through z or '.' 2 or more times (for .co.uk ect domains)

followed by

$ - end of string/line

/ - end regular expression

i - case insensitive search

 

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488805
Share on other sites

First of...thanks Matt for the detailed breakdown.

 

I started writing my first HTML form using the website that was previously given. I have some questions about the following inital attempt at the form:

 

<form method="post" action="mailto:[email protected]">

First Name: <input type="text" size="10" maxlength="40" name="f_name"> <br />

Last Name: <input type="text" size="10" maxlength="40" name="l_name"> <br />

Email: <input type="text" size="10" maxlength="40" name="email"> <br />

 

<input type="submit" value="Send">

</form>

 

As the code is written will it display boxes labled First Name, Last Name and email?

What does the size refer to?

Is maxlength the length of characters it allocates?

Was I correct in changing name= f_name, name= l_name and name=email?

I want to add a box for a telephone number. DO I need to change the input type? If so to what? should I drop maxlength to 10?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488833
Share on other sites

Well assignment said be resourceful :)

 

and if ya dunno the language, creating one on yer own is bout the last thing ya wanna do.

 

Next step, look for a generation script (a script that generates the code for a form for u)

 

Contact form Generator

 

u can prolly find other automated generators :)

 

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488834
Share on other sites

Well assignment said be resourceful :)

 

and if ya dunno the language, creating one on yer own is bout the last thing ya wanna do.

 

Next step, look for a generation script (a script that generates the code for a form for u)

 

Contact form Generator

 

u can prolly find other automated generators :)

 

 

I take it that my HTML form is incorrect. I am trying first to create the form, then add the PHP to it.

Is this the wrong aproach? Is there any help other than a automated script generator that you can offer?

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488863
Share on other sites

The following is a form I created that meets the specifications of the assignment. Now that I have the form how do I add the needed PHP code so that I meet the requirements of the assignment. Thanks again.

 

<form method="post" action="http://www.emailmeform.com/fid.php?formid=59553" enctype="multipart/form-data">

<INPUT TYPE=hidden NAME=FCode VALUE="nbb4xam9">

                 

 

<table cellpadding="2" cellspacing="0" border="0" bgcolor="#FFFFFF">

<tr>

<td>

<font face="Verdana" size="2" color="#000000"></font>

<div style="" id="mainmsg"> </div>

 

</td>

</tr>

</table>

 

<br>

 

<table cellpadding="2" cellspacing="0" border="0" bgcolor="#FFFFFF">

 

<tr valign="top">

<td nowrap><font face="Verdana" size="2" color="#000000">First Name</font></td>

<td>

<input type="text" name="FieldData0" value="" maxlength="100" size="30"> </td>

</tr>     

 

<tr valign="top">

<td nowrap><font face="Verdana" size="2" color="#000000">Last Name</font></td>

<td>

<input type="text" name="FieldData1" value="" maxlength="100" size="30"> </td>

</tr>     

 

<tr valign="top">

<td nowrap><font face="Verdana" size="2" color="#000000">Email</font></td>

<td>

<input type="text" name="FieldData2" value="" maxlength="100" size="30"><div style="position:absolute; top:343px; right:1582px;"><b>Tip: How to delete search history</b><br>Tutorial on how to <a href="http://www.amicutilities.com/privacy-guard/?v=deletehistory">delete search history</a> automated without leaving any traces that make the files recoverable</div> </td>

</tr>     

 

<tr valign="top">

<td nowrap><font face="Verdana" size="2" color="#000000">Telephone</font></td>

<td>

<input type="text" name="FieldData3" value="" maxlength="100" size="30"> </td>

</tr>     

 

<tr>

<td colspan="2">

</td>

</tr>

<tr>

<td> </td>

<td align="right">

<input type="text" name="hida2" value="" maxlength="100" size="3" style="display : none;">

<input type="submit" class="btn" value="Send email" name="Submit"></td>

</tr>

<tr>

<td colspan=2 align="center">

<br>

</td>

</tr>

</table>                     

 

</form>

Link to comment
https://forums.phpfreaks.com/topic/95479-basic-php-assignment/#findComment-488882
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.