Jump to content

Need Help with PHP Validation on my Form


SkarrQ

Recommended Posts

Hi people, i really need help with my PHP code. I have no idea how to do validation on my Form... you know, to make sure that user is editing correct information. I really need help with this one please!!!
 This is how my Form code:

<?php
require 'Controller/BikeController.php';
$BikeController = new BikeController();
$title = "Add a new Bike";
/*******************************************************
Thiese are all the field for Add a new Bike page for editing 
*******************************************************/
$content ="<form action='' method='post'>
    <fieldset>
        <legend>Add a new Bike</legend>
        <label for='name'>Name: </label>
        <input type='text' class='inputField' name='txtName' /><br/>

        <label for='type'>Type: </label>
        <select class='inputField' name='ddlType'>
            <option value='%'>All</option>"
        .$BikeController->CreateOptionValues($BikeController->GetBikeTypes()).
        "</select><br/>

        <label for='price'>Price: </label>
        <input type='text' class='inputField' name='txtPrice' /><br/>

        <label for='roast'>Code: </label>
        <input type='text' class='inputField' name='txtCode' /><br/>

        <label for='discount'>Discount: </label>
        <input type='text' class='inputField' name='txtDiscount' /><br/>

        <label for='image'>Image: </label>
        <select class='inputField' name='ddlImage'>"
        .$BikeController->GetImages().
        "</select></br>
        
        </select></br>

        <label for='review'>Review: </label>
        <textarea cols='70' rows='12' name='txtReview'></textarea></br>

        <input type='submit' value='Submit'>
    </fieldset>
</form>";

/*******************************************************
Calls  function InsertBike()
*******************************************************/
if(isset($_POST["txtName"]))
{
    //$BikeController->InsertBike();
}
include './Templet.php';
?>
                    
Link to comment
Share on other sites

Have you written any php code? That's what we are here to help with, and since you haven't shown us any php code there's nothing for us to help you with.

This is actually a PHP code !!!! If its not, I'm confused.

Link to comment
Share on other sites


<?php
require 'Controller/BikeController.php';
$BikeController = new BikeController();
$title = "Add a new Bike";
/*******************************************************
Thiese are all the field for Add a new Bike page for editing
*******************************************************/
$content ="<form action='' method='post'>
<fieldset>
<legend>Add a new Bike</legend>
<label for='name'>Name: </label>
<input type='text' class='inputField' name='txtName' /><br/>

<label for='type'>Type: </label>
<select class='inputField' name='ddlType'>
<option value='%'>All</option>"
.$BikeController->CreateOptionValues($BikeController->GetBikeTypes()).
"</select><br/>

<label for='price'>Price: </label>
<input type='text' class='inputField' name='txtPrice' /><br/>

<label for='roast'>Code: </label>
<input type='text' class='inputField' name='txtCode' /><br/>

<label for='discount'>Discount: </label>
<input type='text' class='inputField' name='txtDiscount' /><br/>

<label for='image'>Image: </label>
<select class='inputField' name='ddlImage'>"
.$BikeController->GetImages().
"</select></br>

</select></br>

<label for='review'>Review: </label>
<textarea cols='70' rows='12' name='txtReview'></textarea></br>

<input type='submit' value='Submit'>
</fieldset>
</form>";

/*******************************************************
Calls function InsertBike()
*******************************************************/
if(isset($_POST["txtName"]))
{
//$BikeController->InsertBike();
}
include './Templet.php';
?>

Link to comment
Share on other sites

The only php logic/code you are showing us is the part that checks for the existence of the 'txtName' field in your html input. Sure you are using a php echo command to store all the html code but I don't see a script that uses that variable (to output it to the client) nor do I see any code that even attempts to receive the input from your form and try to validate it.

 

How about making a stab at receiving the POST data and doing some reading and attempt to write proper handling code? Then ask for help making it correct.

Link to comment
Share on other sites

As ginerjm mentioned, the PHP code shown is used to display the form. Do you have any code that processes the form submission? Basically, it would help to know where you're stuck? Which field(s) are you looking to validate? And what is considered valid?

 

If you're looking for help on the basics of form validation and/or processing form submissions, there are many resources online:

https://www.google.com/#q=php+form+validation

Edited by cyberRobot
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.