| | |
PHP Form without Java
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 6
Reputation:
Solved Threads: 0
Hi all!
Сonditions of a problem:
1) in one form post info and upload file
2) validation only php without js
3) associated fields: if the value is not the same, we don't need to validate field
4) associated fields: if the value is the same, we need echo new input
And i don't know how make it all in one form without java.
Google and others resource didn't help me
May be you know how or where i can see tutorial for it problem?
I've come to know all w3school, php.net, tizag, tutorials on pixel2life and tutsearch.net, nettuts and even http://www.benjaminkeen.com/software/php_validation/ don't help me.
despair deeply
Сonditions of a problem:
1) in one form post info and upload file
2) validation only php without js
3) associated fields: if the value is not the same, we don't need to validate field
4) associated fields: if the value is the same, we need echo new input
And i don't know how make it all in one form without java.
Google and others resource didn't help me
May be you know how or where i can see tutorial for it problem?I've come to know all w3school, php.net, tizag, tutorials on pixel2life and tutsearch.net, nettuts and even http://www.benjaminkeen.com/software/php_validation/ don't help me.
despair deeply
0
#2 Oct 15th, 2009
Hi catcoffee and welcome to DaniWeb 
1) Can be achieved with a
2) By validation do you mean making sure that the inputted data is acceptable? If so, PHP provides regex functions that can be performed on your $_POST array as well as other ways of validating your form data.
3) and 4) I don't follow what you need here?

1) Can be achieved with a
<input type='file'> in a PHP/HTML form. PHP then uses an array, $_POST, to retrieve all posted data and the $_FILE array to access uploaded files.2) By validation do you mean making sure that the inputted data is acceptable? If so, PHP provides regex functions that can be performed on your $_POST array as well as other ways of validating your form data.
3) and 4) I don't follow what you need here?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. •
•
Join Date: Oct 2009
Posts: 14
Reputation:
Solved Threads: 6
0
#3 Oct 15th, 2009
Did you have a look at http://www.w3schools.com/PHP/php_file_upload.asp in w3schools site? The code clearly explains all steps required to upload a file using HTML and PHP alone.
What are your doubts in points 3 and 4? Can you elaborate on it? Unable to understand and so unable to help
What are your doubts in points 3 and 4? Can you elaborate on it? Unable to understand and so unable to help
•
•
Join Date: Oct 2009
Posts: 6
Reputation:
Solved Threads: 0
0
#4 Oct 15th, 2009
Hi darkagn! Thank you for your answers 
All problems are in associeted fields
example:
If user choice pregnancy field - fields "namebaby" and "agebaby" not required for user.
If user choice onebaby field - fields "namebaby" and "agebaby" required for user, but fields "namebaby1" and "agebaby1" not required for user.
All fields required for user with 2 babies.
I tried insert script in form and call each field
it was bad idea

All problems are in associeted fields
example:
PHP Syntax (Toggle Plain Text)
<form action='<?php echo $_SERVER['SCRIPT_NAME'] ?>' method='post'> //...// <input type="checkbox" name="pregnancy" value="1"/> <input type="checkbox" name="onebaby" value="2"/> <input type="checkbox" name="twobaby" value="3"/> <input type="text" name="namebaby" /> <input type="text" name="agebaby" /> <input type="text" name="namebaby1" /> <input type="text" name="agebaby1" /> //...// <input type="submit" name="btn" value="send"/> </form>
If user choice onebaby field - fields "namebaby" and "agebaby" required for user, but fields "namebaby1" and "agebaby1" not required for user.
All fields required for user with 2 babies.
I tried insert script in form and call each field
PHP Syntax (Toggle Plain Text)
$value = '1'; echo "<input type='checkbox' name='pregnancy' value='1'/> Pregnancy?"; if (isset($_POST['pregnancy'])) { // if ($_POST['pregnancy'] == $value) { $pregnanc = true; } else { // No value $pregnanc = false; } if ($pregnanc) { print 'happy'; } else { echo "<input type='text' name='namebaby' />"; }
•
•
Join Date: Oct 2009
Posts: 99
Reputation:
Solved Threads: 18
First off, your HTML form needs to look like this
Notice the enctype="multipart/form-data" , this tells the browser that a file needs to be encoded with this form.
Next up, you need to change the 'baby' field to a radio button so the user can only select one option. Set the appropriate values (0, 1 and 2) so you know which one is selected.
Your PHP validation should be something like this
Obviously this is a very simple form handling technique. But it should be good enough for your purposes. Close thread if this is the solution or continue with your query
PHP Syntax (Toggle Plain Text)
<form action='<?php echo $_SERVER['SCRIPT_NAME'] ?>' enctype="multipart/form-data" action='' method='post'> //...// <input type="radio" name="num_babies" value="0"/> <input type="radio" name="num_babies" value="1"/> <input type="radio" name="num_babies" value="2"/> <input type="text" name="namebaby" /> <input type="text" name="agebaby" /> <input type="text" name="namebaby1" /> <input type="text" name="agebaby1" /> //...// <input type="submit" name="btn" value="send"/> </form>
Notice the enctype="multipart/form-data" , this tells the browser that a file needs to be encoded with this form.
Next up, you need to change the 'baby' field to a radio button so the user can only select one option. Set the appropriate values (0, 1 and 2) so you know which one is selected.
Your PHP validation should be something like this
PHP Syntax (Toggle Plain Text)
<?php <?php $babyField = isset($_POST['num_babies']) ? $_POST['num_babies'] : 0; //if num babies is set, it takes that value //otherwise it assigns 0 switch ($babyField) { //This will manage our baby types more easily case 0: //Type is preganancy //No names are required break; case 1: //One baby if ($_POST['namebaby'] == "") {}//Error do something if ($_POST['agebaby'] == "") {}//Error do something break; case 2: //two babies if ($_POST['namebaby'] == "") {}//Error do something if ($_POST['agebaby'] == "") {}//Error do something if ($_POST['namebaby1'] == "") {}//Error do something if ($_POST['agebaby1'] == "") {}//Error do something break; default: //Just in case someone got smart and put an invalid field. so we break; } ?> ?>
Obviously this is a very simple form handling technique. But it should be good enough for your purposes. Close thread if this is the solution or continue with your query
Last edited by jomanlk; Oct 16th, 2009 at 11:26 am. Reason: accidentally submitted before I was done
![]() |
Similar Threads
- PHP Form submit to email (PHP)
- PHP Form Validation ??? (PHP)
- php form - pop-up window possible? (PHP)
- Sending an image to email via PHP form? (PHP)
- How to redirect in a php form ? (PHP)
- PHP form being used externally i think (PHP)
- Php Form (PHP)
- Sending pic attachments via PHP form (PHP)
Other Threads in the PHP Forum
| Thread Tools | Search this Thread |
ajax archive array basic beginner button c# checkbox class cms code codes creat curl data database delete developers display dom dynamic email external file files flash flex form forms forum gentoo google hosting html image include insert java javascript jobs jquery js keywords lamp libcurl limit link login longisland mail memmory menu methods multiple multipletables mysql object oop open password pdf php post problem programming projectmanager query remove robot script search searchbox security seo session sessions simple sms smtp spam sql subscription system table tutorial upload user validation video virus visual web webbrowser website window xml xslt yahoo youtube zend






