Jump to content

Basic Quickform Validation


majiren

Recommended Posts

Hello,

 

Firstly let me explain I am just getting into php - so please be gentle  ;)

 

Basically the user enters from a product page - they have selected a few radio buttons which have now been passed to "page2"

 

My problem though is that on loading of this page the form already thinks its missing some data from the user (we have just arrived!!)

 

Sorry if this is a bit long winded (I have said I'm a beginner  :-\ ) -- If anyone could give me a little help on this I would be very thankful

 

<?php

 

 

$product_1 = 'unchecked';

$product_2 = 'unchecked';

 

if (isset($_POST['productsform'])) {

//the client has requested a quote on a few products

//For the end mail

$selected_product1 = $_POST['product_number1'];

$selected_product2 = $_POST['product_number2'];

$selected_product3 = $_POST['product_number3'];

$selected_product4 = $_POST['product_number4'];

$selected_product5 = $_POST['product_number5'];

$selected_product6 = $_POST['product_number6'];

$selected_product7 = $_POST['product_number7'];

$selected_product8 = $_POST['product_number8'];

$selected_product9 = $_POST['product_number9'];

$selected_product10 = $_POST['product_number10'];

$selected_product11 = $_POST['product_number11'];

$selected_product12 = $_POST['product_number12'];

$selected_product13 = $_POST['product_number13'];

$selected_product14 = $_POST['product_number14'];

$selected_product15 = $_POST['product_number15'];

 

 

//Confirm what he has selected

//add product number 1

if ($_POST['product_number1']){echo '<br />You have selected Product 1';

$order_product1 = '1001';

}

//add product number 2

if ($_POST['product_number2']){echo '<br />You have selected Product 2';

$order_product2 = '1002';

}

//add product number 3

if ($_POST['product_number3']){echo '<br />You have selected Product 3';

$order_product3 = '1003';

}

//add product number 4

if ($_POST['product_number4']){echo '<br />You have selected Product 4';

$order_product4 = '1004';

}

//add product number 5

if ($_POST['product_number5']){echo '<br />You have selected Product 5';

$order_product5 = '1005';

}

//add product number 6

if ($_POST['product_number6']){echo '<br />You have selected Product 6';

$order_product6 = '1006';

}

//add product number 7

if ($_POST['product_number7']){echo '<br />You have selected Product 7';

$order_product7 = '1007';

}

//add product number 8

if ($_POST['product_number8']){echo '<br />You have selected Product 8';

$order_product8 = '1008';

}

//add product number 9

if ($_POST['product_number9']){echo '<br />You have selected Product 9';

$order_product9 = '1009';

}

//add product number 10

if ($_POST['product_number10']){echo '<br />You have selected Product 10';

$order_product10 = '10010';}

//add product number 11

if ($_POST['product_number11']){echo '<br />You have selected Product 11';

$order_product11 = '10011';}

//add product number 12

if ($_POST['product_number12']){echo '<br />You have selected Product 12';

$order_product12 = '10012';}

//add product number 13

if ($_POST['product_number13']){echo '<br />You have selected Product 13';

$order_product13 = '10013';}

//add product number 14

if ($_POST['product_number14']){echo '<br />You have selected Product 14';

$order_product14 = '10014';}

//add product number 15

if ($_POST['product_number15']){echo '<br />You have selected Product 15';

$order_product15 = '10015';}

 

//end of information from page1

}

 

 

else {

 

?>

<br/>

A table with all the products - the user can choose one, because they haven't already!

<br />

<?php

 

}

 

//include the Quickform class

require_once 'HTML/QuickForm.php';

 

//Include the phpmailer class

require_once($_SERVER['DOCUMENT_ROOT'].'/usb-direct/mail/lib/phpmailer/class.phpmailer.php');

##########################################################

      # The user information would normally come from a database

      $user = array("firstname"=>"Mickey",

                    "lastname"=>"Mouse",

                    "sal_id"=>4,

                    "user_id"=>7);

      # 'Salutation' comes from a lookup table comprising

      # sal_id, sal_text

      $salutations = array("0"=>"Mr",

                          "1"=>"Miss",

                          "2"=>"Mrs",

                          "3"=>"Dr",

                          "4"=>"Sir");

      $capacities = array("0"=>"128-Mb",

                          "1"=>"256-Mb",

                          "2"=>"520-Mb",

                          "3"=>"1-Gb",

                          "4"=>"2-Gb");

      # End of "database-retrieved" information

      ##########################################################

 

 

 

//Instanciate Quickform

$form = new HTML_Quickform('imageUpload', 'POST');

$form->addElement('header', 'MyHeader', 'Recieve a Quote');

 

$form->addElement('select', 'sal_id', '', $salutations);

//Add the Enquirer's Name

$form->addElement('text', 'enq_name', 'Your Name: ');

$form->addRule('enq_name', 'Please enter a name', 'required', NULL, 'client');

 

//Add the Enquirer's email

$form->addElement('text', 'enq_email', 'Your Email: ');

$form->addRule('enq_email', 'Please enter an email address', 'required', NULL, 'client');

$form->addRule('enq_email', 'Please enter a valid email address', 'email', NULL, ' client');

 

//This is where you will want to put in capacity, color, etc.

$form->addElement('select', 'enq_capacity', '', $capacities);

 

 

 

 

 

//The file upload field

$form->addElement('file', 'image', 'If you have a logo file: ');

$form->addRule('image', 'The maximum file size is 56k', 'maxfilesize', 57344);

$form->addRule('image', 'the file must be animage', 'mimetype', array('image/gif', 'image/jpg', 'image/png'));

$form->addRule('image', 'No file selected.', 'uploadfile', NULL, 'client');

 

//Add a message from enquirer

$form->addElement('textarea', 'enq_message', 'Remarks: ');

 

//Submit Button

$form->addElement('submit', 'submit', 'Send');

 

 

 

// Try to validate a form

if ($form->validate()) {

   

    //get info

$enq_name = $form->getSubmitValue('enq_name');

$enq_email = $form->getSubmitValue('enq_email');

$enq_message = $form->getSubmitValue('enq_message');

 

//end of info

 

//Start of Email

echo '<h4>Hello, we have a new enquirey from '.$enq_name.' </h4>';

    echo '<br /> <p>'.$enq_name.' has a message: &nbsp '.$enq_message.'

    <br />

<p>Thank you for your prompt reply,</p>

 

Support

';

    //End of Email

   

}

 

// Output the form

$form->display();

 

 

 

?>

</form>

 

I hope you can see what I'm trying to do here...

 

Cheers for any insight into this code,

 

majiren

Link to comment
https://forums.phpfreaks.com/topic/40818-basic-quickform-validation/
Share on other sites

Sorry maybe I'll give you my website.. http://www.usb-direct.net

 

From the products page to the "request a quote" - if you select some products it will go to the page (above code) and the quickform will of already ?validated? and give you the red rules  :(

 

How to stop this from happening?

 

cheers,

 

majiren

Erm, ok so it appears to be working?!  :-\ 

 

However, after the form is submited it doesn't go back to the page? Any ideas? Also if anybody has a suggestion of how to tidy this code up I would be very interested (a rough direction would be great) I'm still at the very BASIC stage.

 

thank you,

 

maj

Sorry but i dont get to see the pic for the sticks where are they.

 

also the time load with all those pics are to long cut the pic size down with a pic editor ok.

 

 

you need to shorten the page ok make the pic smaller on the main page any other page i can not see the pic's ok.

Thanks for your tips guys..  I'm still in the testing stage so don't really need those pics there.

 

Anyway my biggest problem at the moment is that once submitting the form it will return to another page... not go back to this one...if you have any tips for my problem I would thank you a million times!

 

cheers,

 

majiren

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.