PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Jul 20, 2018 3:58 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 42 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Sun Jun 10, 2012 4:27 am 
Offline
Forum Contributor

Joined: Tue Jan 10, 2012 7:05 am
Posts: 462
i have a form that now needs to be saved if it isn't complete, what the best way of doing this without making a whole new form.

i have included the whole form below.
Syntax: [ Download ] [ Hide ]
<?php
error_reporting(E_ALL);
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  //$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO plus_signup (terms, prop_id, StartDate, weeks, EndDate, Title, userid, password, sex, DOBDate, DOBMonth, DOBYear, Nationality, `Marital Status`, PhoneDay, PhoneEvening, PhoneMobile, email, Smoker, NextKin, CurrentAddress, PrevAddress, LivingStatus, Student, BankFinCCJ, BankFinArrears, BankFinBankR, BankFinNone, BankName, BankAccNum, BankSortCode, BankDuration, BankDCard, BankElectoral, LLName, LLTele, LLEmail, LLHost, LLAddress, GuName, GuTitle, GuDobDate, GuDobMonth, GuDobYear, GuSex, GuMarital, GuPhoneDay, GuPhoneEven, GuPhoneMob, GuPhoneEmail, GuCurrentAdd, GuPrevAdd, GuBankName, GuBankAccNu, GuBankSort, GuBankDurat, GuBankDebit, GuBankElect, GuEmpProffes, GuEmpAnnWa, GuEmpPayroll, GuSelfEmp, GuHaveAcc, GuAccName, GuAccContName, GuAccAdd, GuAccDayTel, GuAccMobTel, GuAccEmail, GuAccAdditional, GuEmployerNam, GuEmployerAdd, GuEmployerContactName, GuEmployerTele, GuEmployerEmail, GuEmployerCCj, GuEmployerArr, GuEmployerBankR, GuEmployerNone) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString(isset($_POST['terms']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['prop_id'], "text"),
                       GetSQLValueString($_POST['StartDate'], "text"),
                       GetSQLValueString($_POST['weeks'], "text"),
                       GetSQLValueString($_POST['EndDate'], "text"),
                       GetSQLValueString($_POST['Title'], "text"),
                       GetSQLValueString($_POST['userid'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['sex'], "text"),
                       GetSQLValueString($_POST['DOBDate'], "text"),
                       GetSQLValueString($_POST['DOBMonth'], "text"),
                       GetSQLValueString($_POST['DOBYear'], "text"),
                       GetSQLValueString($_POST['Nationality'], "text"),
                       GetSQLValueString($_POST['Marital_Status'], "text"),
                       GetSQLValueString($_POST['PhoneDay'], "text"),
                       GetSQLValueString($_POST['PhoneEvening'], "text"),
                       GetSQLValueString($_POST['PhoneMobile'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['Smoker'], "text"),
                       GetSQLValueString($_POST['NextKin'], "text"),
                       GetSQLValueString($_POST['CurrentAddress'], "text"),
                       GetSQLValueString($_POST['PrevAddress'], "text"),
                       GetSQLValueString($_POST['LivingStatus'], "text"),
                       GetSQLValueString($_POST['Student'], "text"),
                       GetSQLValueString(isset($_POST['BankFinCCJ']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString(isset($_POST['BankFinArrears']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString(isset($_POST['BankFinBankR']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString(isset($_POST['BankFinNone']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['BankName'], "text"),
                       GetSQLValueString($_POST['BankAccNum'], "text"),
                       GetSQLValueString($_POST['BankSortCode'], "text"),
                       GetSQLValueString($_POST['BankDuration'], "text"),
                       GetSQLValueString($_POST['BankDCard'], "text"),
                       GetSQLValueString($_POST['BankElectoral'], "text"),
                       GetSQLValueString($_POST['LLName'], "text"),
                       GetSQLValueString($_POST['LLTele'], "text"),
                       GetSQLValueString($_POST['LLEmail'], "text"),
                       GetSQLValueString($_POST['LLHost'], "text"),
                       GetSQLValueString($_POST['LLAddress'], "text"),
                       GetSQLValueString($_POST['GuName'], "text"),
                       GetSQLValueString($_POST['GuTitle'], "text"),
                       GetSQLValueString($_POST['GuDobDate'], "text"),
                       GetSQLValueString($_POST['GuDobMonth'], "text"),
                       GetSQLValueString($_POST['GuDobYear'], "text"),
                       GetSQLValueString($_POST['GuSex'], "text"),
                       GetSQLValueString($_POST['GuMarital'], "text"),
                       GetSQLValueString($_POST['GuPhoneDay'], "text"),
                       GetSQLValueString($_POST['GuPhoneEven'], "text"),
                       GetSQLValueString($_POST['GuPhoneMob'], "text"),
                       GetSQLValueString($_POST['GuPhoneEmail'], "text"),
                       GetSQLValueString($_POST['GuCurrentAdd'], "text"),
                       GetSQLValueString($_POST['GuPrevAdd'], "text"),
                       GetSQLValueString($_POST['GuBankName'], "text"),
                       GetSQLValueString($_POST['GuBankAccNu'], "text"),
                       GetSQLValueString($_POST['GuBankSort'], "text"),
                       GetSQLValueString($_POST['GuBankDurat'], "text"),
                       GetSQLValueString($_POST['GuBankDebit'], "text"),
                       GetSQLValueString($_POST['GuBankElect'], "text"),
                       GetSQLValueString($_POST['GuEmpProffes'], "text"),
                       GetSQLValueString($_POST['GuEmpAnnWa'], "text"),
                       GetSQLValueString($_POST['GuEmpPayroll'], "text"),
                                           GetSQLValueString($_POST['GuSelfEmp'], "text"),
                                           GetSQLValueString($_POST['GuHaveAcc'], "text"),
                                           GetSQLValueString($_POST['GuAccName'], "text"),
                                           GetSQLValueString($_POST['GuAccContName'], "text"),
                                           GetSQLValueString($_POST['GuAccAdd'], "text"),
                                           GetSQLValueString($_POST['GuAccDayTel'], "text"),
                                           GetSQLValueString($_POST['GuAccMobTel'], "text"),
                                           GetSQLValueString($_POST['GuAccEmail'], "text"),
                                           GetSQLValueString($_POST['GuAccAdditional'], "text"),
                       GetSQLValueString($_POST['GuEmployerNam'], "text"),
                       GetSQLValueString($_POST['GuEmployerAdd'], "text"),
                       GetSQLValueString($_POST['GuEmployerContactName'], "text"),
                       GetSQLValueString($_POST['GuEmployerTele'], "text"),
                       GetSQLValueString($_POST['GuEmployerEmail'], "text"),
                       GetSQLValueString(isset($_POST['GuEmployerCCj']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString(isset($_POST['GuEmployerArr']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString(isset($_POST['GuEmployerBankR']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString(isset($_POST['GuEmployerNone']) ? "true" : "", "defined","'Y'","'N'"));

  mysql_select_db($database_hostprop, $hostprop);
  $Result1 = mysql_query($insertSQL, $hostprop) or die(mysql_error());

        // Auto Login User
        if (!isset($_SESSION)) {
                session_start();
        }

        $_SESSION['MM_Username'] = $_POST['userid'];
    $_SESSION['MM_UserGroup'] = "";      
       
        // Redirect user to make-payment.php
        // With relevant POST Data
        $post_data = array("amount"=>250,"type"=>"deposit");
        $content_length = strlen($post_data);
        $_SESSION['post_data'] = $post_data;
        header("location: http://www.student.com/make-payment.php");
        exit();

}

mysql_select_db($database_hostprop, $hostprop);
$query_rsApplyNow = "SELECT * FROM host_editprop WHERE available = 0";
$rsApplyNow = mysql_query($query_rsApplyNow, $hostprop) or die(mysql_error());
$row_rsApplyNow = mysql_fetch_assoc($rsApplyNow);
$totalRows_rsApplyNow = mysql_num_rows($rsApplyNow);
?>


<form class="cmxform"action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
    <input type="hidden" name="MM_insert" value="form2" />


------all form content is on here---------

                <input type="submit" value="submit" />
     </form>
 

so basically if they cant complete the form i want another button to be added so the information is saved to the DB.....

When they start the form the have to provide a username and password, this can be used to log back in and complete the form when needed

thanks
Jon


Last edited by pickle on Mon Jun 11, 2012 11:22 am, edited 1 time in total.
Wrapping huge code block in syntax tags


Top
 Profile  
 
PostPosted: Mon Jun 11, 2012 1:49 am 
Offline
Forum Contributor
User avatar

Joined: Wed Dec 23, 2009 1:28 pm
Posts: 201
AJAX


Top
 Profile  
 
PostPosted: Mon Jun 11, 2012 2:20 am 
Offline
Forum Contributor

Joined: Tue Jan 10, 2012 7:05 am
Posts: 462
ok well where do i start? do i have to build a wholew new form?


Top
 Profile  
 
PostPosted: Mon Jun 11, 2012 5:06 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za
jonnyfortis wrote:
ok well where do i start? do i have to build a wholew new form?

A new form isn't necessary, just additions to your existing one. Your best option is to do a search for this type of thing using a search engine, an online tutorial will do a better job of explain the ideas behind the code than someone here just giving you the code :)

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Mon Jun 11, 2012 7:40 am 
Offline
Forum Contributor

Joined: Tue Jan 10, 2012 7:05 am
Posts: 462
ok i will search for an online tutorial.

thanks for your time


Top
 Profile  
 
PostPosted: Mon Jun 11, 2012 11:24 am 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6444
Location: 53.01N x 112.48W
AJAX isn't strictly necessary.

One option would be to have a second button on your form labelled "Save". On the page that the form is submitted to, you can check which button was used to submit the form, and act accordingly. If you have multiple <input type = "submit"> elements, only the one that was clicked will be sent in $_POST.

_________________
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.


Top
 Profile  
 
PostPosted: Mon Jun 11, 2012 11:57 am 
Offline
Forum Contributor

Joined: Sat Mar 27, 2004 6:54 am
Posts: 194
Is there any reason you couldn't just simply allow the user to edit their information later? ie save whatever data has been entered (makes no difference if complete or not) [perhaps add a field to the table "completed", where 1 is the form has been fully filled out and 0 is form needs more data] , then when they log in check the completed, if o - advise user and display form in editable mode


Top
 Profile  
 
PostPosted: Tue Jun 12, 2012 5:10 am 
Offline
Forum Contributor

Joined: Tue Jan 10, 2012 7:05 am
Posts: 462
>>>>>>Is there any reason you couldn't just simply allow the user to edit their information later? ie save whatever data has been entered (makes no difference if complete or not) [perhaps add a field to the table "completed", where 1 is the form has been fully filled out and 0 is form needs more data] , then when they log in check the completed, if o - advise user and display form in editable mode.


yes that would be an idea but im not sure how i would implement the script


Top
 Profile  
 
PostPosted: Tue Jun 12, 2012 5:12 am 
Offline
Forum Contributor

Joined: Tue Jan 10, 2012 7:05 am
Posts: 462
>>>>>>>>>>>>>>>>>>>>>>>>>>>AJAX isn't strictly necessary.

One option would be to have a second button on your form labelled "Save". On the page that the form is submitted to, you can check which button was used to submit the form, and act accordingly. If you have multiple <input type = "submit"> elements, only the one that was clicked will be sent in $_POST.


can you go into a bit more depth on what you mean because it sound like this is something that could work

thanks


Top
 Profile  
 
PostPosted: Tue Jun 12, 2012 9:41 am 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6444
Location: 53.01N x 112.48W
First off, there is a "quote" button beside everyone's reply that lets you quote their post - no need for >>>>>>>>>> (FYI)

What I meant was this:
Syntax: [ Download ] [ Hide ]
<form>
    <input type = "text" name = "first_name" />
    ... and so on ...
    <input type = "submit" name = "save" value = "Save form" />
    <input type = "submit" name = "submit" value = "Submit form" />
</form>

If someone clicks the "Save form" button, $_POST will have a "first_name" and "save" element, but not a "submit" element. Similarly if someone clicks the "Submit form" button, $_POST will have a "first_name" and a "submit" element, but not a "save" element.

_________________
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.


Top
 Profile  
 
PostPosted: Wed Jun 13, 2012 6:12 am 
Offline
Forum Contributor

Joined: Tue Jan 10, 2012 7:05 am
Posts: 462
ok thanks i think i understand, will see what i can come up with

regards


Top
 Profile  
 
PostPosted: Wed Jun 13, 2012 6:23 am 
Offline
Forum Contributor

Joined: Tue Jan 10, 2012 7:05 am
Posts: 462
pickle wrote:
First off, there is a "quote" button beside everyone's reply that lets you quote their post - no need for >>>>>>>>>> (FYI)

What I meant was this:
Syntax: [ Download ] [ Hide ]
<form>
    <input type = "text" name = "first_name" />
    ... and so on ...
    <input type = "submit" name = "save" value = "Save form" />
    <input type = "submit" name = "submit" value = "Submit form" />
</form>

If someone clicks the "Save form" button, $_POST will have a "first_name" and "save" element, but not a "submit" element. Similarly if someone clicks the "Submit form" button, $_POST will have a "first_name" and a "submit" element, but not a "save" element.




when you say a "save element" do you mean there will be a save in the if statement and a save in the DB? aswell as all the other feilds? so there will be 2 if statement with all the other feilds and one with a save and one with a submit?


Top
 Profile  
 
PostPosted: Wed Jun 13, 2012 6:40 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za
If the 'save' button is clicked you will have $_POST['save'] in the $_POST array so you can test for it's presence like this
Syntax: [ Download ] [ Hide ]
<?php
 if (isset($_POST['save']) && $_POST['save'] == 'Save form') {
   // save button clicked, execute corresponding code
 }
?>

An easy method to see this in action is to do a var_dump() or print_r() of $_POST on the page that processes the script
Syntax: [ Download ] [ Hide ]
<?php
 print_r($_POST);
?>

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 3:35 am 
Offline
Forum Contributor

Joined: Tue Jan 10, 2012 7:05 am
Posts: 462
social_experiment wrote:
If the 'save' button is clicked you will have $_POST['save'] in the $_POST array so you can test for it's presence like this
Syntax: [ Download ] [ Hide ]
<?php
 if (isset($_POST['save']) && $_POST['save'] == 'Save form') {
   // save button clicked, execute corresponding code
 }
?>

An easy method to see this in action is to do a var_dump() or print_r() of $_POST on the page that processes the script
Syntax: [ Download ] [ Hide ]
<?php
 print_r($_POST);
?>


i am confused where this would go. i have created the save and submit buttons on the page but i am unsure where to put the

if (isset($_POST['save']) && $_POST['save'] == 'Save form') {
// save button clicked, execute corresponding code
}

as i already have

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {

in the code, does your code site above this?


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 4:47 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za
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
Syntax: [ Download ] [ Hide ]
<?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
 }
}
?>

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group