Page 2 of 3

Re: form with two buttons one saving form other submit

Posted: Thu Jun 14, 2012 5:01 am
by jonnyfortis
social_experiment wrote:
jonnyfortis wrote:in the code, does your code site above this?
For arguments sake yes; below is a snippet of conditional code on how to check which button was clicked

Code: Select all

<?php
if (isset($_POST['save']) && $_POST['save'] == 'Save form') {
// save button clicked, execute corresponding code
}
else {
 // now the save button isn't clicked but you have to check if the 
 // submit button was clicked
 if (isset($_POST['submit']) && $_POST['submit'] == 'Submit form') {
     // submit button clicked, execute corresponding code
 }
}
?>


ok i now understand the else statement. if the save button is clicked the it will $_POST the information to the DB and if the submit button is clicked the it will $_POST the information to the DB? if i am doing this the db fields will have to be set to not null?? is this correct or i will have to put a value in the field?

or am i thinking too much!!

Re: form with two buttons one saving form other submit

Posted: Thu Jun 14, 2012 6:14 am
by social_experiment
jonnyfortis wrote:if the save button is clicked the it will $_POST the information to the DB and if the submit button is clicked the it will $_POST the information to the DB?
If the script writes it to the database in both instances then yes it will go to the DB.
jonnyfortis wrote:if i am doing this the db fields will have to be set to not null?? is this correct or i will have to put a value in the field?
You will place the values in the fields yes, could you explain how the 'null' value figure into this? do you mean set the default value of the column to 'null'?

Re: form with two buttons one saving form other submit

Posted: Thu Jun 14, 2012 7:29 am
by jonnyfortis
social_experiment wrote:
jonnyfortis wrote:if the save button is clicked the it will $_POST the information to the DB and if the submit button is clicked the it will $_POST the information to the DB?
If the script writes it to the database in both instances then yes it will go to the DB.
jonnyfortis wrote:if i am doing this the db fields will have to be set to not null?? is this correct or i will have to put a value in the field?
You will place the values in the fields yes, could you explain how the 'null' value figure into this? do you mean set the default value of the column to 'null'?
well what i mean by the "not null" is if they haven't completed the form and they try and post it to the db then if they haven't finished the for then it will return a value of the field cant be null. so i ideally wanted to put a default value in the db fields.

Let me explain the full process of the form. They can either apply using a form from the start MM_insert POST. They enter all the information ( if they don't have the information i want them to be able to return at later date to input). They have to enter a username and password to be able to access their account to continue to edit the form.

if they complete the form straight away it takes them to the next page and all sorted. However...

if they want to save the form this is where they have to enter their user details then login and access the form ( which is a different page to the first POST form) this in an GET MM_update. So i need to have data in the db feilds saying "required" so the form passes.

i hope this is clear what i am trying to achieve

Thanks in advance

Re: form with two buttons one saving form other submit

Posted: Thu Jun 14, 2012 7:54 am
by social_experiment
jonnyfortis wrote:well what i mean by the "not null" is if they haven't completed the form and they try and post it to the db then if they haven't finished the for then it will return a value of the field cant be null. so i ideally wanted to put a default value in the db fields.
ok; then setting the default value to null will be useful.
jonnyfortis wrote:if they want to save the form this is where they have to enter their user details then login and access the form ( which is a different page to the first POST form) this in an GET MM_update. So i need to have data in the db feilds saying "required" so the form passes.
For required fields (on a form) you would probably want to do a check before the form is submitted; as well as after the form has been processed.

Re: form with two buttons one saving form other submit

Posted: Thu Jun 14, 2012 8:53 am
by jonnyfortis
social_experiment wrote:
jonnyfortis wrote:well what i mean by the "not null" is if they haven't completed the form and they try and post it to the db then if they haven't finished the for then it will return a value of the field cant be null. so i ideally wanted to put a default value in the db fields.
ok; then setting the default value to null will be useful.

yes now i have added required to all fields (as all fields are required)
jonnyfortis wrote:if they want to save the form this is where they have to enter their user details then login and access the form ( which is a different page to the first POST form) this in an GET MM_update. So i need to have data in the db feilds saying "required" so the form passes.
For required fields (on a form) you would probably want to do a check before the form is submitted; as well as after the form has been processed.
ok i have jquery prompts on the form that they can fill in from the start ($_post) this works fine
the form that uses GET i have the required feilds so obviously there is the "required" text in each field then the jquery will not work.

So i am still a bit lost on the save in both forms though

Re: form with two buttons one saving form other submit

Posted: Thu Jun 14, 2012 9:31 am
by social_experiment
jonnyfortis wrote:So i am still a bit lost on the save in both forms though
with this i take it that you are refering to writing the information to the database?

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 1:38 am
by jonnyfortis
social_experiment wrote:
jonnyfortis wrote:So i am still a bit lost on the save in both forms though
with this i take it that you are refering to writing the information to the database?

yes thats correct, i am still unsure of what goes where

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 2:13 am
by social_experiment
The code you want to execute when the save button is clicked goes inside the first if loop while the code for the submit button will be placed in the second if loop if you are using this snippet below as reference. If you're refering to the actual code that writes to the database you would have to paste existing code you have so we can assist you

Code: Select all

<?php
if (isset($_POST['save']) && $_POST['save'] == 'Save form') {
// save button clicked, execute corresponding code
}
else {
 // now the save button isn't clicked but you have to check if the 
 // submit button was clicked
 if (isset($_POST['submit']) && $_POST['submit'] == 'Submit form') {
     // submit button clicked, execute corresponding code
 }
}
?>

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 4:36 am
by jonnyfortis
social_experiment wrote:
jonnyfortis wrote:in the code, does your code site above this?
For arguments sake yes; below is a snippet of conditional code on how to check which button was clicked

Code: Select all

<?php
if (isset($_POST['save']) && $_POST['save'] == 'Save form') {
// save button clicked, execute corresponding code
}
else {
 // now the save button isn't clicked but you have to check if the 
 // submit button was clicked
 if (isset($_POST['submit']) && $_POST['submit'] == 'Submit form') {
     // submit button clicked, execute corresponding code
 }
}
?>

ok i added the code but the trouble is i have jquery alerts on the page that prompt for the feilds to be filled in. how can i get around this?


<script type="text/javascript" src="js/jquery.js"></script>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.17.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="js/date.format.js"></script>
<script src="lib/jquery.metadata.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$().ready(function() {

// validate signup form on keyup and submit
$("#form2").validate({
rules: {
StartDate: "required",
EndDate: "required",
Nationality: "required",
PhoneDay: "required",
PhoneEvening: "required",
PhoneMobile: "required",
NextKin: "required",
CurrentAddress: "required",
PrevAddress: "required",
BankName: "required",
BankAccNum: "required",
BankSortCode: "required",
BankDuration: "required",
LLName: "required",
LLTele: "required",
LLEmail: "required",
LLAddress: "required",
GuName: "required",
GuPhoneDay: "required",
GuPhoneEven: "required",
GuPhoneMob: "required",
GuPhoneEmail: "required",
GuCurrentAdd: "required",
GuPrevAdd: "required",
GuBankName: "required",
GuBankAccNu: "required",
GuBankSort: "required",
GuBankDurat: "required",
GuEmpProffes: "required",
GuEmpAnnWa: "required",
GuEmpPayroll: "required",
GuAccName: "required",
GuAccContName: "required",
GuAccAdd: "required",
GuAccDayTel: "required",
GuAccMobTel: "required",
GuAccEmail: "required",
GuEmployerNam: "required",
GuEmployerAdd: "required",
GuEmployerContactName: "required",
GuEmployerTele: "required",
GuEmployerEmail: "required",
userid: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
email: {
required: true,
email: true
},
terms: "required"
},
messages: {
StartDate: "Please select a start date",
EndDate: "Please select an end date",
Nationality: "Please enter your nationality",
PhoneDay: "Please enter a daytime phone number",
PhoneEvening: "Please enter a evening phone number",
PhoneMobile: "Please enter a mobile number",
NextKin: "Please enter your next of kin",
CurrentAddress: "Please enter a current address",
PrevAddress: "Please enter a previous address",
BankName: "Please enter your bank name",
BankAccNum: "Please enter your account number",
BankSortCode: "Please enter your sort code",
BankDuration: "Please enter your bank duration",
LLName: "Please enter landlords name",
LLTele: "Please enter landlords telephone number",
LLEmail: "Please enter landlords email address",
LLAddress: "Please enter landlords address",
GuName: "Please enter guarantor name",
GuPhoneDay: "Please enter guarantor phone number",
GuPhoneEven: "Please enter guarantor evening number",
GuPhoneMob: "Please enter guarantor mobile number",
GuPhoneEmail: "Please enter guarantor email address",
GuCurrentAdd: "Please enter guarantor current address",
GuPrevAdd: "Please enter previous address",
GuBankName: "Please enter guarantor bank name",
GuBankAccNu: "Please enter guarantor account number",
GuBankSort: "Please enter guarantor sort code",
GuBankDurat: "Please enter guarantor bank duration",
GuEmpProffes: "Please enter guarantor proffesion",
GuEmpAnnWa: "Please enter guarantor annual wage",
GuEmpPayroll: "Please enter guarantor payroll number",
GuAccName: "Please enter guarantor accountant name",
GuAccContName: "Please enter guarantors accountant contact",
GuAccAdd: "Please enter guarantors accountants address",
GuAccDayTel: "Please enter guarantors accountants daytime numbers",
GuAccMobTel: "Please enter guarantors accountants mobile",
GuAccEmail: "Please enter guarantors accountants email",
GuAccAdditional: "Please enter guarantors accounts additional info",
GuEmployerNam: "Please enter guarantors employers name",
GuEmployerAdd: "Please enter guarantors employers address",
GuEmployerContactName: "Please enter guarantors employers contact",
GuEmployerTele: "Please enter enter guarantors employers number",
GuEmployerEmail: "Please enter guarantors employers email",
userid: {
required: "Please enter a user ID",
minlength: "Your username must consist of at least 2 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
confirm_password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
},
email: "Please enter a valid email address",
terms: "Please accept our policy"

}

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 5:55 am
by social_experiment
jonnyfortis wrote:but the trouble is i have jquery alerts on the page that prompt for the feilds to be filled in. how can i get around this?
Functions. You can probably create a single function and thus minimize your code; The is a javascript example

Code: Select all

function checkRequiredField(id, message)
{
 var fieldValue = document.getElementById(id).value;
 if (fieldValue == '') {
    alert(message);
    return false;
 }
}
In html that creates the form there can be something similar to this

Code: Select all

<input type="text" name="email" id="email" size="30" onblur="checkRequiredField('email', 'This needs a valid email address');" />
You can customize this approach as needed; key thing is that it will cut down on the amount of code used for your client-side validation.

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 6:02 am
by jonnyfortis
social_experiment wrote:
jonnyfortis wrote:but the trouble is i have jquery alerts on the page that prompt for the feilds to be filled in. how can i get around this?
Functions. You can probably create a single function and thus minimize your code; The is a javascript example

Code: Select all

function checkRequiredField(id, message)
{
 var fieldValue = document.getElementById(id).value;
 if (fieldValue == '') {
    alert(message);
    return false;
 }
}
In html that creates the form there can be something similar to this

Code: Select all

<input type="text" name="email" id="email" size="30" onblur="checkRequiredField('email', 'This needs a valid email address');" />
You can customize this approach as needed; key thing is that it will cut down on the amount of code used for your client-side validation.
i did use something like this before but i have radio buttons check boxes as well so it was getting confusing...

shall i delete all the jquery stuff i have in the form add your code just form the form feilds ( add defaults for the radios and check boxes) and then we can concentrate on the save as and submit values?

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 7:20 am
by social_experiment
jonnyfortis wrote:shall i delete all the jquery stuff i have in the form add your code just form the form feilds
best to make a copy of existing code; if you decide the old code works better you still have a copy somewhere

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 7:30 am
by jonnyfortis
social_experiment wrote:
jonnyfortis wrote:shall i delete all the jquery stuff i have in the form add your code just form the form feilds
best to make a copy of existing code; if you decide the old code works better you still have a copy somewhere

ok if i go down the route and use this code will this take out the problem of all fields being required? i have taken a back up of the form as it is now so can revert back to that as need be

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 10:07 am
by social_experiment
jonnyfortis wrote:ok if i go down the route and use this code will this take out the problem of all fields being required?
It will make all the fields in the form "required"; anyone wanting to submit the form needs to complete each field before they can submit it; note: this is only effective if a user has javascript enabled; you need to do a server side validation aswell - you check the values that are submitted and if they are empty the user has to fill in the form again

Re: form with two buttons one saving form other submit

Posted: Fri Jun 15, 2012 10:24 am
by jonnyfortis
social_experiment wrote:
jonnyfortis wrote:ok if i go down the route and use this code will this take out the problem of all fields being required?
It will make all the fields in the form "required"; anyone wanting to submit the form needs to complete each field before they can submit it; note: this is only effective if a user has javascript enabled; you need to do a server side validation aswell - you check the values that are submitted and if they are empty the user has to fill in the form again

but obviously if they want to save the application they will not have to complete the form??