Making the HTML code for the frame

Posted on Updated on

Image result for Making the HTML code for the frameMaking the HTML code for the frame

In HTML, a frame is starts and finishes with a <form> tag. The shape label encompasses every one of the contributions and additionally gives directions about how and where to present the frame. For instance, how about we begin making a frame in a document named myform.php.

<form action=”myform.php” method=”post”>

<!- – shape fields go here – >

</form>

The “activity” indicates what page to present the frame to. Commonly, the activity will be an indistinguishable page from the frame. The “technique” shows how the frame is submitted. There are two techniques: “get” and “post”. More often than not, structures will utilize the “post” strategy.( more on get and post ) Presently how about we add a few contributions to the frame. How about we include a content field that requests your most loved motion picture and a submit catch to present the frame.

<form action=”myform.php” method=”post”>

Which is your most loved motion picture?

<input type=”text” name=”formMovie” maxlength=”50″>

<input type=”submit” name=”formSubmit” value=”Submit”>

</form>

Getting the shape information

The contribution of sort “content” is only a solitary line field to sort in some content. We give it a name of “formMovie” which we will utilize later amid handling. Maxlength just shows that the program shouldn’t give the client a chance to sort more than 50 characters into the content box.

Congrats! You now have a frame that will submit. It doesn’t do much yet, and whatever you write in “leaves” when you submit.

We should add some PHP to process this shape:

<?php

if($_POST[‘formSubmit’] == “Submit”)

{

$varMovie = $_POST[‘formMovie’];

}

?>

<form action=”myform.php” method=”post”>

Which is your most loved film?

<input type=”text” name=”formMovie” maxlength=”50″>

<input type=”submit” name=”formSubmit” value=”Submit”>

</form>

In the first place, recollect that this frame “submits to itself”, implying that the shape factors will be sent to this page, and the page will stack again from the top.

In this way, the main thing we ought to do is to check and check whether a shape was submitted or not. To do that, how about we take a gander at the estimation of the “formSubmit” catch. In the event that its esteem is “Submit”, then we know a shape has been submitted. If not, then the client is likely going to this page surprisingly. To get to this esteem, utilize the $_POST[‘inputname’] cluster, where “inputname” is the name in the HTML component. We utilize “$_POST” since that is the shape’s strategy. In the event that it was “get” rather, we’d utilize $_GET[].

Second, after we’ve confirmed that the shape was presented, how about we get the content that the client wrote. Once more, we utilize the $_POST exhibit to get the esteem and place it into the $varMovie variable.

At long last, we’ve included an “esteem” field to the formMovie input box, and put some PHP code in there to set the esteem equivalent to whatever the client entered. This implies on the off chance that you present the frame, the content you wrote in will in any case show up in that content box. This is critical when there are different contributions, as we will see later with approval.

So now we have a frame that still doesn’t do much. We should include another contribution before going into approval.

<?php

if($_POST[‘formSubmit’] == “Submit”)

{

$varMovie = $_POST[‘formMovie’];

$varName = $_POST[‘formName’];

}

?>

<form action=”myform.php” method=”post”>

Which is your most loved film?

<input type=”text” name=”formMovie” maxlength=”50″ value=”<?=$varMovie;?>”>

What is your name?

<input type=”text” name=”formName” maxlength=”50″ value=”<?=$varName;?>”>

<input type=”submit” name=”formSubmit” value=”Submit”>

</form>

Approving the info

Assume we have a client who neglected to enter one of the fields? We have to approve the shape to ensure it’s total and rounded out with legitimate data. Take note of that you can utilize JavaScript for this, yet that JavaScript can be effortlessly killed: dependably approve in the server-side script, regardless! ( The JavaScript shape approval script can help you include JavaScript approvals rapidly. )

Approvals should be possible with straightforward PHP if proclamations. When you have to include more sorts of approvals rapidly, checkout the PHP shape approval script.

<?php

if($_POST[‘formSubmit’] == “Submit”)

{

$errorMessage = “”;

if(empty($_POST[‘formMovie’]))

{

$errorMessage .= “<li>You neglected to enter a movie!</li>”;

}

if(empty($_POST[‘formName’]))

{

$errorMessage .= “<li>You neglected to enter a name!</li>”;

}

$varMovie = $_POST[‘formMovie’];

$varName = $_POST[‘formName’];

if(!empty($errorMessage))

{

echo(“<p>There was a mistake with your form:</p>\n”);

echo(“<ul>” . $errorMessage . “</ul>\n”);

}

}

?>

In this illustration, the code makes some extremely fundamental verifies that the client wrote in something –anything–into both of the info fields. In the event that the client didn’t, each check will add another visual cue to the mistake message. At long last, when it’s set making approvals, it will verify whether there is a mistake message. In the event that there is, it shows it. In the event that there are no mistakes, it shows a win message.

Take note of that if there are mistakes or not, any data that was gone into the frame sources of info is saved. Thusly a client doesn’t need to round out the whole shape again on the off chance that they overlooked only a certain something.

Sparing the information to a document

At last, we should take this information and compose it into a content record.

<?php

if($errorMessage != “”)

{

echo(“<p>There was an error:</p>\n”);

echo(“<ul>” . $errorMessage . “</ul>\n”);

}

else

{

$fs = fopen(“mydata.csv”,”a”);

fwrite($fs,$varName . “, ” . $varMovie . “\n”);

fclose($fs);

header(“Location: thankyou.html”);

exit;

}

?>

The fopen work opens up a CSV document in “an” (affix) mode. This implies if mydata.csv as of now exists, it will indicate the finish of the record. If not, it will make the document and point toward the begin. Next, the fwritefunction takes the document pointer made by fopen and composes the name and motion picture isolated by a comma and completion with a carriage return. At long last, the pointer to the document is shut. Presently, every time a legitimate shape is presented, a name and motion picture will be composed to mydata.csv.

On account of the way frame information is “posted” to web server, hitting the revive catch on the program will bring about a similar thing to happen each time it is clicked after the shape is submitted. Along these lines, for the most part you ought to divert to another page to maintain a strategic distance from invigorate catch issues. Make a “thankyou.html” HTML page that says “thank you for presenting your motion picture” or whatever.

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666

Email:info@technocampus.co.in

**************************************************************************************************************

Please fill the FORM and we shall contact you soon.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s