Jump to content

Recommended Posts

I may aswell give you the whole run down as it isnt very long......

 

Ok, so i have my own website which i have managed to scrape together using basic html and a touch of Java. I decided i needed to add a few forms though. The way i have learned anything to do with the web so far is to deconstruct what ever i like on a web site using the "view source" button and then reconstruct it to what i need.

 

The first went pretty well, it's a basic one page photo submission form:

http://www.reticulatedpython.info/content/information/photosubmission.html

 

Then i did an email request one:

http://www.reticulatedpython.info/content/index2.html

 

Then it came to the more complex one which requires several "pages". The idea is to register an animal, and depending on the parentage be able to give varying information about the animal. The end of the form should result in 3 photos being uploaded to my server and the form details added to a file, along with an email sent to me to say info had been added.

 

This is what i've come up with for the form itself:

http://www.reticulatedpython.info/forms/registry/form1.html

(That directory also holds processor.php)

 

However, it isnt working right and i havent got a clue why or where to look to fix it. I know i'm in well over my head but i would appreciate some help  :confused:

 

Link to comment
https://forums.phpfreaks.com/topic/180916-i-was-doing-so-well/
Share on other sites

I know the code isnt right here because i changed a drop down to a check box and havent gotten to editing this yet.

 

<?php

$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

// Checkbox handling
$field_5_opts = $_POST['field_5'][0].",". $_POST['field_5'][1].",". $_POST['field_5'][2];

// Checkbox handling
$field_11_opts = $_POST['field_11'][0].",". $_POST['field_11'][1];

// Checkbox handling
$field_13_opts = $_POST['field_13'][0].",". $_POST['field_13'][1];

// File upload handling
if($_FILES['field_15']['name']!=''){
$field_15_filename = "file_15_".date("sihdmY").substr($_FILES['field_15']['name'],strlen($_FILES['field_15']['name'])-4);
if(!move_uploaded_file($_FILES['field_15']['tmp_name'], "./files/".$field_15_filename)){
die("File " .  $_FILES['field_15']['name'] . " was not uploaded.");
}
}

// File upload handling
if($_FILES['field_16']['name']!=''){
$field_16_filename = "file_16_".date("sihdmY").substr($_FILES['field_16']['name'],strlen($_FILES['field_16']['name'])-4);
if(!move_uploaded_file($_FILES['field_16']['tmp_name'], "./files/".$field_16_filename)){
die("File " .  $_FILES['field_16']['name'] . " was not uploaded.");
}
}

// File upload handling
if($_FILES['field_17']['name']!=''){
$field_17_filename = "file_17_".date("sihdmY").substr($_FILES['field_17']['name'],strlen($_FILES['field_17']['name'])-4);
if(!move_uploaded_file($_FILES['field_17']['tmp_name'], "./files/".$field_17_filename)){
die("File " .  $_FILES['field_17']['name'] . " was not uploaded.");
}
}

// Checkbox handling
$field_22_opts = $_POST['field_22'][0].",". $_POST['field_22'][1];

// Checkbox handling
$field_25_opts = $_POST['field_25'][0].",". $_POST['field_25'][1];

// File upload handling
if($_FILES['field_27']['name']!=''){
$field_27_filename = "file_27_".date("sihdmY").substr($_FILES['field_27']['name'],strlen($_FILES['field_27']['name'])-4);
if(!move_uploaded_file($_FILES['field_27']['tmp_name'], "./files/".$field_27_filename)){
die("File " .  $_FILES['field_27']['name'] . " was not uploaded.");
}
}

// File upload handling
if($_FILES['field_28']['name']!=''){
$field_28_filename = "file_28_".date("sihdmY").substr($_FILES['field_28']['name'],strlen($_FILES['field_28']['name'])-4);
if(!move_uploaded_file($_FILES['field_28']['tmp_name'], "./files/".$field_28_filename)){
die("File " .  $_FILES['field_28']['name'] . " was not uploaded.");
}
}

// File upload handling
if($_FILES['field_29']['name']!=''){
$field_29_filename = "file_29_".date("sihdmY").substr($_FILES['field_29']['name'],strlen($_FILES['field_29']['name'])-4);
if(!move_uploaded_file($_FILES['field_29']['tmp_name'], "./files/".$field_29_filename)){
die("File " .  $_FILES['field_29']['name'] . " was not uploaded.");
}
}

// Checkbox handling
$field_31_opts = $_POST['field_31'][0].",". $_POST['field_31'][1];

// Checkbox handling
$field_34_opts = $_POST['field_34'][0].",". $_POST['field_34'][1];

// File upload handling
if($_FILES['field_36']['name']!=''){
$field_36_filename = "file_36_".date("sihdmY").substr($_FILES['field_36']['name'],strlen($_FILES['field_36']['name'])-4);
if(!move_uploaded_file($_FILES['field_36']['tmp_name'], "./files/".$field_36_filename)){
die("File " .  $_FILES['field_36']['name'] . " was not uploaded.");
}
}

// File upload handling
if($_FILES['field_37']['name']!=''){
$field_37_filename = "file_37_".date("sihdmY").substr($_FILES['field_37']['name'],strlen($_FILES['field_37']['name'])-4);
if(!move_uploaded_file($_FILES['field_37']['tmp_name'], "./files/".$field_37_filename)){
die("File " .  $_FILES['field_37']['name'] . " was not uploaded.");
}
}

// File upload handling
if($_FILES['field_38']['name']!=''){
$field_38_filename = "file_38_".date("sihdmY").substr($_FILES['field_38']['name'],strlen($_FILES['field_38']['name'])-4);
if(!move_uploaded_file($_FILES['field_38']['tmp_name'], "./files/".$field_38_filename)){
die("File " .  $_FILES['field_38']['name'] . " was not uploaded.");
}
}

// Checkbox handling
$field_40_opts = $_POST['field_40'][0].",". $_POST['field_40'][1];

// Checkbox handling
$field_43_opts = $_POST['field_43'][0];

// File upload handling
if($_FILES['field_45']['name']!=''){
$field_45_filename = "file_45_".date("sihdmY").substr($_FILES['field_45']['name'],strlen($_FILES['field_45']['name'])-4);
if(!move_uploaded_file($_FILES['field_45']['tmp_name'], "./files/".$field_45_filename)){
die("File " .  $_FILES['field_45']['name'] . " was not uploaded.");
}
}

// File upload handling
if($_FILES['field_46']['name']!=''){
$field_46_filename = "file_46_".date("sihdmY").substr($_FILES['field_46']['name'],strlen($_FILES['field_46']['name'])-4);
if(!move_uploaded_file($_FILES['field_46']['tmp_name'], "./files/".$field_46_filename)){
die("File " .  $_FILES['field_46']['name'] . " was not uploaded.");
}
}

// File upload handling
if($_FILES['field_47']['name']!=''){
$field_47_filename = "file_47_".date("sihdmY").substr($_FILES['field_47']['name'],strlen($_FILES['field_47']['name'])-4);
if(!move_uploaded_file($_FILES['field_47']['tmp_name'], "./files/".$field_47_filename)){
die("File " .  $_FILES['field_47']['name'] . " was not uploaded.");
}
}

$fileLine = "Title: " . $_POST['field_1'] . " 
Country: " . $_POST['field_2'] . " 
Email: " . $_POST['field_3'] . " 
Forum ID: " . $_POST['field_4'] . " 
Snake origin: $field_5_opts
FirstName: " . $_POST['field_6'] . " 
Mother: " . $_POST['field_7'] . " 
Father: " . $_POST['field_8'] . " 
Arrival Date: " . $_POST['field_9'] . " 
Date of birth: " . $_POST['field_10'] . " 
Sex: $field_11_opts
Age: " . $_POST['field_12'] . " 
Available for breeding loan: $field_13_opts
Distinguishing features: " . $_POST['field_14'] . " 
Head photo: " . $_POST['field_15'] . " 
Neck photo : " . $_POST['field_16'] . " 
Full body photo: " . $_POST['field_17'] . " 
Morph/Locality: " . $_POST['field_18'] . " 
referrer: " . $_POST['field_19'] . " 
Mothers morph/locality: " . $_POST['field_20'] . " 
Fathers morph/locality: " . $_POST['field_21'] . " 
Sex of snake to be added: $field_22_opts
Age: " . $_POST['field_23'] . " 
Morph/Locality of snake to be added: " . $_POST['field_24'] . " 
Available for breeding loan: $field_25_opts
Distinguishing features: " . $_POST['field_26'] . " 
Head photo: " . $_POST['field_27'] . " 
Neck photo: " . $_POST['field_28'] . " 
Full body photo: " . $_POST['field_29'] . " 
Mothers morph/locality: " . $_POST['field_30'] . " 
Sex of snake to be added: $field_31_opts
Age: " . $_POST['field_32'] . " 
Morph/locality: " . $_POST['field_33'] . " 
Available for breeding loan: $field_34_opts
Distinguishing features: " . $_POST['field_35'] . " 
Head photo: " . $_POST['field_36'] . " 
Neck photo: " . $_POST['field_37'] . " 
Full body photo: " . $_POST['field_38'] . " 
Fathers morph/locality: " . $_POST['field_39'] . " 
Sex of snake to be added: $field_40_opts
Age: " . $_POST['field_41'] . " 
Morph/locality: " . $_POST['field_42'] . " 
Available for breeding loan: $field_43_opts
Distinguishing features: " . $_POST['field_44'] . " 
Head photo: " . $_POST['field_45'] . " 
Neck photo: " . $_POST['field_46'] . " 
Full body photo: " . $_POST['field_47'] . " 

";
$filename = 'registry.txt';
if (is_writable($filename)) {

		    if (!$handle = fopen($filename, 'a'))
		    {
		         echo "Cannot open file ($filename)";
		         exit;
		    }
		    if (fwrite($handle, $fileLine) === FALSE) {
		        echo "Cannot write to file ($filename)";
		        exit;
		    }

		    fclose($handle);

		} else {
		    echo "The file  is not writable";
		}

include("confirm.html");

?>

 

 

My biggest concern is getting the actual form script to go to the right pages when the right options are selected. I think i can do the rest from there, i think.....

Link to comment
https://forums.phpfreaks.com/topic/180916-i-was-doing-so-well/#findComment-954463
Share on other sites

i'd definitely look into using a mysql database for this site hey,

your codes just going to get harder if your pulling/deleting/updating records from .txt files and searching records etc etc.

 

My biggest concern is getting the actual form script to go to the right pages when the right options are selected

do you mean the form posts to different pages depending on the option selected... or the form always posts to processor.php which redirects the user to a page depending on options selected?

 

if so what options??

 

you'd have to have a thing like

 

switch ($_POST['pageOption'])
{
case 'Big Snake':
    header('location: bigsnake.html');
    exit();
case 'Small Snake':
    header('location: smallsnake.html');
    exit();
default:
    header('location: error.html');
    exit();
}

 

or you could do the same with if statements, but switch is better for this situation...

http://php.net/manual/en/control-structures.switch.php

 

Link to comment
https://forums.phpfreaks.com/topic/180916-i-was-doing-so-well/#findComment-954478
Share on other sites

Firstly, i gave you the wrong link, genius that i am  :shy:

I have attached a copy of the code behind the form i am trying to use to this post.

 

Unfortunately my current hosting package doesnt allow for me to use Mysql so that's not an option.

I only set it as a .txt file so i could easily identify it when i first started the script.

As for the data held in the file (that the form adds), it is never going to be a massively popular feature so the content will never be more than i can handle using the "find" option in notepad for editing.

 

Within form.php there are 6 elements - mainForm_1-mainForm_6 (i call each one a page, which may have confused things, sorry)

What i wanted to do was have the user fill out mainForm_1 and depending on the options selected they would go to different mainForm elements after that, a process which would continue with each element selected until the end where the data was sent to the file.

 

I tried to do this using the if statement but it wont work that way for some reason.

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/180916-i-was-doing-so-well/#findComment-954488
Share on other sites

if you have php then you have a db. http://php.about.com/od/learnphp/qt/php_flat_file.htm

although sql is popular  and easy, it has security risks and is overkill for most of the applications its used for.

 

Care to explain how a flat file is a database, or what the inherent security issues that you are claiming are related to SQL are? 

Link to comment
https://forums.phpfreaks.com/topic/180916-i-was-doing-so-well/#findComment-954495
Share on other sites

Firstly, i gave you the wrong link, genius that i am  :shy:

I have attached a copy of the code behind the form i am trying to use to this post.

 

Unfortunately my current hosting package doesnt allow for me to use Mysql so that's not an option.

I only set it as a .txt file so i could easily identify it when i first started the script.

As for the data held in the file (that the form adds), it is never going to be a massively popular feature so the content will never be more than i can handle using the "find" option in notepad for editing.

 

Within form.php there are 6 elements - mainForm_1-mainForm_6 (i call each one a page, which may have confused things, sorry)

What i wanted to do was have the user fill out mainForm_1 and depending on the options selected they would go to different mainForm elements after that, a process which would continue with each element selected until the end where the data was sent to the file.

 

I tried to do this using the if statement but it wont work that way for some reason.

 

 

So, the first thing I wanted to state up front was that it does indeed sound like a database would be very beneficial to you.  If you can't use mysql, you might be able to use an alternative like sqllite or even bdb (berkeley db).  There's just a huge advantage to having structured data and indexed retrieval available to you.  I'm not sure what you're paying, but I know of all sorts of $6/ month shared hosting companies that give you a full LAMP stack as well.

 

 

So on to the bad news -- being that I perused your script, and quite frankly it already borders on spaghetti.  Doing naming based on page numbers in a multi-form process is just asking for trouble -- what happens in the future when you realize that page 2 & 3 should be combined, page 5 eliminated, and page 7 updated?  You will regret that I predict. 

 

I don't have the time or patience to go through and start rewriting code, but I think your best bet would be to begin by asking yourself why you are trying to make something so complicated.  Is this really something that can't be done in one single form?  Javascript is also very helpful for linking things together, especially if the interrelated choices are going to be static.

Link to comment
https://forums.phpfreaks.com/topic/180916-i-was-doing-so-well/#findComment-954508
Share on other sites

Ok, so firstly, i was genuinely trying to make it easy, not complicated  :P

 

This could be done in a single form but lots of fields are a pain in the ass and scare people off, i wanted to make sure that only fields that were relevant were presented to people.

 

I'm going to have a look at the other database suggestions you made, see what i can come up with.

 

Thankyou all for your help

Link to comment
https://forums.phpfreaks.com/topic/180916-i-was-doing-so-well/#findComment-954512
Share on other sites

I understand you had the best intentions -- it's just that the approach you've taken thus far is already hard to read. It seems you have the basics, and you can certainly build upon it, although at present I'm not even sure I know what your current problem or bug is.

 

I did take a look at your site, and if this is going to be a database of pythons, I don't know that the people who would fill that out are really going to be all that upset if they have a bunch of columns to fill out -- in fact, you may find that you piss people off more, by trying to hide a lenghty multi-form approach.  At the end of the day, you will need to validate the input before you accept it, whether you have 5 interconnected forms or one big one.

 

Just my 2 cents. 

 

If you have a specific question, I'd be glad to take a look at it, as would others.  I think we lost the thread on what your exact problem is at the moment.

 

 

Link to comment
https://forums.phpfreaks.com/topic/180916-i-was-doing-so-well/#findComment-954522
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.