![]() |
|
#1
|
|||
|
|||
Trouble with SessionsHi, all! I need some help with session. I'm building a a site that will us sessions to collect data from multiple pages as the user submits the forms by pressing the submit buttom. Once the form is submitted the $_POST[' something'] vars will be past to a scrip for processing. (Script: form.php)
I am able to start the session with session_start(); and register some variables, but when users complete the form submision process an e-mail will all the data should be sent to an e-mail address, but it doesn't work. Here is the script I wrote: PHP Code:
What am I doing wrong? I want to collect user info using multiple forms. I then want to send admin an e-mail. Once that is done I want to sore the users info in a mysql database. (<-Comming soon) Sites Example: Like this -> http://www.theloanengine.com Could someone help! Thanks! Last edited by LuciWiz : 06-Jan-2006 at 15:41.
Reason: Please insert your Php code between [php] & [/php] tags
|
|
#2
|
|||
|
|||
Re: Trouble with SessionsNow I'm not entirely sure on this, but are you sure that PHP can recognize this as a valid email?
"Javier Lopez" <jalopez13@yahoo.com> That is an outlook formatted e-mail with the contact name in front. in the mail() function the first part of it is just supposed to be a strict email address. If you tried just PHP Code:
That might cause the email to actually reach somewhere if that email is valid? At least that is what I am thinking... |
|
#3
|
|||
|
|||
Re: Trouble with SessionsActually I just read up on it further on php.net.
What you did was semi-okay. By that I mean you can do what you did, just without quotes. For example: PHP Code:
Quote:
You should place debugging scripts inside of your code to help you better find the source of the problem. For instance: PHP Code:
This will show something like what mysql_error() would show, an error message of why this code didn't work. If it doesn't show you an error at all, either it sent the email this time, or the error lies before the mail() line itself. In that case you will have to place debug scripts like this on all of your PHP functions to see which one is causing the script to halt. Those are really the only suggestions I can give to you. |
|
#4
|
|||
|
|||
Re: Trouble with SessionsThanks for the help Samuri! I was able to get the mail() to work. Now the problem is that when the e-mail goes out it doesn't populate all the $_POST['something']. It only populates the $_POST['some'] coming from <input type=text name=var value=var> but the $_POST['saomthing'] coming from <select name=var> </select> do not populate using regiserted session vars as...$_SESSION['somthing'] = $_POST['somthing']. What can I do to get the vars to populate with multi-select form fields? Also, I have two image buttons in a form that I haven't been able to write a script for that i'm using as navigational elements. What I want is to have the (Boback button) go back once pressed and the (continue button) to go forward once pressed. I'm using to hidden form fields to set values to both buttons. See example below:
<input type=hidden name=goToStep value=2> <input type=hidden name=goBackTo value=1> See site for example. http://www.mortgage-bay.com. If you could help pleasse do. I'm going nuts trying to come up with a schem to make this site fully functional. Thank for all you help so far! Ohm_ |
|
#5
|
|||
|
|||
Re: Trouble with SessionsHeh, I think I know why. Because I've ran into this before. What I am getting from your information is that all your <input> fields return fine (they are populating). But your <select></select> fields aren't. Here is the reason:
<input type="text" name="testfield"> Whatever info is typed into that box is returned. That is what we like to call a voluntary field. As in, the user enters the information manually. Select Fields (drop down boxes) do not work like that. <select name="testfield2"> <option>Opt 1</option> <option>Opt 2</option> </select> Essentially this will create a dropdown box with two options, Opt 1 and Opt 2. But that doesn't matter. PHP still won't recognize it. You need to set each option inside of the select box with a value="". For instance, lets take the same example the way you are SUPPOSED to do it: <select name="testfield2"> <option value="Opt 1">Opt 1</option> <option value="Opt 2">>Opt 2</option> </select> PHP only sees the value="" part, and EXACTLY the way it appears in there <option value="blah">Test</option> In that example PHP returns "blah" not Test, regardless of what comes in between, php needs a value before you can $_POST[] it from the form. Give that a try and let me know if it fixes your problem. |
|
#6
|
|||
|
|||
Re: Trouble with SessionsAs far as those buttons, I don't think what you have will work, although I've never tried what you are doing. Answer me this, when you go back you want it to save the form information the person entered, is that correct? Or just a general place to go back. I would use a simple JavaScript command to go between certain areas of the page
<img src="blah.jpg" onClick="self.location.href='www.link.com' "> You can put a specific link in the self.location.href....but as far as your other buttons, I don't really know what you were trying to do. If you can provide a specific link to each step for instance... Step 1: form.php?step=1 Step 2: form.php?step=2 With this you can make the PHP return what step you are on by using $_GET[] which retreives from the URL it self...if you are on step 1 then $_GET['step'] would return 1. Then essentially; Previous Button: <img src="previous.jpg" onClick="self.location.href='form.php?step=1' "> Next Button: <img src="previous.jpg" onClick="self.location.href='form.php?step=2' "> To make those images into submit buttons (for the purpose of the form)...just put type="submit" into each of those image codes. |
|
#7
|
|||
|
|||
Re: Trouble with SessionsOk, this is what I'm using and trying to accomplish.
Here is my site set up: php pages: Templates: index.php site_header.tpl step2.php site_footer.tpl step3.php index.tpl step4.php step2.tpl thankyou.php step3.tpl form.php step4.tpl thankyou.tpl I'm using smarty for templating and Sessions to keep any vars (expample. $_POST['something']) to be available through out the site. I place the session_start(); in each of the .php pages as follows... /* <? //Session Start session_name('session_name'); session_start(); //full path to Smarty.class.php require('Smarty/Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = 'templates/'; $smarty->compile_dir = 'templates_c/'; $smarty->cache_dir = 'cache/'; $smarty->config_dir = 'configs/'; $smarty->assign('title', 'Title'); $smarty->display('index.tpl'); ?> */ Then once the first form is submitted from the index.php page I want to register the session var $_SESSION['name'] using my script form.php. once the index is submitted from there on the script(form.php) will handle the navigation from page to page and register all the $_SESSION['name'] vars to form.php. Once the last page is submitted (step4.php) and all the $_SESSION['name'] vars are registered the user will be sent to thankyou.php and session will end and a e-mail with all the collected $_SESSION vars will be sent to the administrator. The navigation can be done by javascript as you stated or by php, I just want it to work and i'm trying to find the most conviniant way to do it. This is my form.php script. /* <? session_name('form'); session_start(); //Registered Session Vars $_SESSION['submit_1'] = $_POST['submit_1']; $_SESSION['submit_2'] = $_POST['submit_2']; $_SESSION['submit_3'] = $_POST['submit_3']; $_SESSION['submit_4'] = $_POST['submit_4']; $_SESSION['goToStep'] = $_POST['goToStep']; $_SESSION['goBackTo'] = $POST['goBackTo']; //Regiserted Form Session Vars //Page 4. $_SESSION['first_name'] = $_POST['first_name']; $_SESSION['last_name'] = $_POST['last_name']; $_SESSION['address'] = $_POST['address']; $_SESSION['city'] = $_POST['city']; $_SESSION['stateCode'] = $_POST['stateCode']; $_SESSION['zipcode'] = $_POST['zipcode']; $_SESSION['day_npa'] = $_POST['day_npa']; $_SESSION['day_nxx'] = $_POST['day_nxx']; $_SESSION['day_station'] = $_POST['day_station']; $_SESSION['day_ext'] = $_POST['day_ext']; $_SESSION['eve_npa'] = $_POST['eve_npa']; $_SESSION['eve_nxx'] = $_POST['eve_nxx']; $_SESSION['eve_station'] = $_POST['eve_station']; $_SESSION['email'] = $_POST['email']; $_SESSION['BestTime'] = $_POST['BestTime']; //Page 3. $_SESSION['annualIncome'] = $_POST['annualIncome']; $_SESSION['occupational_status'] = $_POST['occupational_status']; $_SESSION['monthlyDebtPayments'] = $_POST['monthlyDebtPayments']; $_SESSION['bankruptcy'] = $_POST['bankruptcy']; //Page 2. $_SESSION['loan_purpose'] = $_POST['loan_purpose']; $_SESSION['homepurchaseyear'] = $_POST['homepurchaseyear']; $_SESSION['home_value_preset'] - $POST['home_value_preset']; $_SESSION['mortgage1_balance'] = $_POST['mortgage1_balance']; $_SESSION['m1IrDDa'] = $POST['m1IrDDa']; $_SESSION['m1IrDDb'] = $POST['m1IrDDb']; $_SESSION['mortgageRateType'] = $POST['mortgageRateType']; $_SESSION['second_mortgage'] = $_POST['second_mortgage']; $_SESSION['m2IrDDa'] = $_POST['m2IrDDa']; $_SESSION['m2IrDDb'] = $POST['m2IrDDb']; //Page 1. $_SESSION['propertyStateCode'] = $_POST['propertyStateCode']; $_SESSION['propertyDesc'] = $_POST['propertyDesc']; $_SESSION['credit_rating'] = $_POST['credit_rating']; $_SESSION['typeOfLoan'] = $_POST['typeOfLoan']; //Forward Nav if (isset($_POST['submit_1'])) { echo (require_once('step2.php')); exit; }elseif (isset($_POST['submit_2'])) { echo (require_once('step3.php')); exit; }elseif (isset($_POST['submit_3'])) { echo (require_once('step4.php')); exit; }elseif (isset($_POST['submit_4'])) { echo (require_once('thankyou.php')); exit; }else { echo "There has beed a problem processing you request. Please contact us at 1-888-285-9974. We apologies for the inconviniance."; } // send email function function sendemail() { $emailTo = '"Administrator" <Administrator@yahoo.com>'; $emailSubject = "Form: My Site"; $emailHeader = "From: {$_SESSION['email']}\n" . "Reply-To: {$_SESSION['email']}\n" . "MIME-Version: 1.0\n" . "Content-type: text/plain; charset=\"ISO-8859-1\"\n" . "Content-transfer-encoding: quoted-printable\n"; $emailBody = " " ."Mortgage Quote Request\n" ."\n" ."\n" ."Contact Information" . "\n" . "First Name:..................:{$_POST['first_name']}\n" . "Last Name:...................:{$_POST['last_name']}\n" . "Address:.......................:{$_POST['address']}\n" . "City:..............................:{$_POST['city']}\n" . "State:............................:{$_POST['stateCode']}\n" . "Zip Code:......................:{$_POST['zipcode']}\n" . "Preferred Number:.......:{$_POST['day_npa']}.{$_POST['day_nxx']}.{$_POST['day_station']}.{$_POST['day_ext']}\n" . "Alternate Number:.......:{$_POST['eve_npa']}.{$_POST['eve_nxx']}.{$_POST['eve_station']}\n" . "Email:...........................:{$_POST['email']}\n" . "Best Time to Call:.........:{$_POST['BestTime']}\n" ." \n" . "Property Information\n" ."\n" . "Subject Property State:..:{$_POST['propertyStateCode']}\n" . "Subject Description:.......:{$_POST['propertyDesc']}\n" . "Credit Rating:.................:{$_POST['credit_rating']}\n" . "Loan Type:......................:{$_POST['typeOfLoan']}\n" . "Loan Purpose:.................:{$_POST['refi_purpose']}\n" . "Property Purchased:.......:{$_POST['homepurchaseyear']}\n" . "Estimate Value:..............:{$_POST['home_value_preset']}\n" . "Other Value:...................:{$_POST['home_value_other']}\n" . "Mortgage Balance:..........:{$_POST['mortgage1_balance']}\n" . "Current Rate:.................:{$_POST['m1IrDDa']}.{$_POST['m1IrDDb']}\n" . "Mortgage Type:...............:{$_POST['mortgageRateType']}\n" . "Second Mortgage:...........:{$_POST['second_mortgage']}\n" . "2nd Current Balance:......:{$_POST['mortgage2_balance']}\n" . "Current Rate:..................:{$_POST['m2IrDDa']}.{$_POST['m2IrDDb']}\n" . "\n" . "Income Incormation\n" . "\n" . "Annual Income:..............:{$_POST['annualIncome']}\n" . "Occupation:....................:{$_POST['occupational_status']}\n" . "Est. Monthly debt:..........:{$_POST['monthlyDebtPayments']}\n" . " Bankruptcy:...................:{$_POST['bankruptcy']}\n" . "\n" . " \n "; mail($emailTo, $emailSubject, $emailBody, $emailHeader) or trigger_error("Error:", E_USER_ERROR); } //Final Submission E-mail Function if(isset($_POST['submit_4'])) { sendemail(); } else { echo " Our server encountered an error. Your information was not sent."; } ?> */ I'm currently using $_POST['submit_1...2...3...4'] to trigger the navigation and to trigger when to send the e-mail. FYI Please help! I'm new to php and no nothing about javascrip. I'm a graphic designer learning php. Thank Sam! |
|
#8
|
|||
|
|||
Re: Trouble with SessionsI see. This is quite a big job to start your PHP career! But all the same a great one to learn quite a bit from as well.
Did the select boxes populate after you fixed the value fields? You should get that working first. Other than that, the most convenient way to move from page to page with an image (while still keeping the data) is just to use easy HTML hrefs <a></a> and then preload the session like you are already doing, the data is already saved inside of the session, and as long as you session_start() the php page, everything should be fine. That I would say is the most convenient way to do it, just do: Current Page: step2.php Previous Button: <a href="step1.php"><img src="previous.jpg"></a> Next Button <a href="step3.php"><img src="next.jpg"></a> I would just do it like that, instead of trying to make buttons out of em, easiest way if you are using sessions. But fix that emailer first, see if those dropdown boxes populate. They should if you make sure you have value="" in the <select> tags. |
|
#9
|
|||
|
|||
Re: Trouble with SessionsSam, I tried your seggestion of using...
"Current Page: step2.php Previous Button: <a href="step1.php"><img src="previous.jpg"></a> Next Button <a href="step3.php"><img src="next.jpg"></a> ...and it didn't work. The images I'm trying to use are both within the <form> <Img= back> <img=continue> </form> elements. Because the "continue" <img> is being used to submit the form data and the "back" <img> is within the <form> <img=back> </form> elements, the form data is submitted regardles of whether you press the "continue" or "back" button. Adding i <a href="step3.php"><input type=image src="/images/tle_continue.gif" border=0></a> does not work. Any further suggestions? Let me know and thanks for all your help! |
|
#10
|
|||
|
|||
Re: Trouble with SessionsWell your continue button has to be a submit button or image no doubt about that. Here is what we will have to do. It is going to have to be javascript to work the continue button. First of all give your form a name (it has to have a name or this won't work):
<form name="myform" action="step2.php" method="post"> Then we put the image inside of it and use javascript to make it submit the data, this is the only way to do this unless you know style sheets but you really can't make the button as fancy as you have it already, so lets do this instead. Here is how: <A HREF="javascript:document.myform.submit()" onclick="return val_form_this_page()"> <IMG SRC="continue.jpg" border="0" ALT="Submit Form"> </A> Note the document.myform.submit(). The "myform" part of that has to be the same name as the name you gave to the form, or this won't work. This javascript is fairly simple and will submit the form for you and allows you to use the image. The onclick submits the form upon the image being clicked, and the val_form_this_page() is just a simple thing that validates the form returning true or false, and if it is true, the form is then submitted. then end the tag with <form> and put everything else you had in the form above that <a></a> tag. Hope this helps!! |
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| feof() trouble | Lewk of Serthic | C Programming Language | 5 | 14-Sep-2005 23:43 |
| C programming trouble | Newworld | C Programming Language | 8 | 12-Sep-2004 23:06 |
| Having trouble trying to format C: | Nickster64 | Computer Software Forum - Windows | 2 | 27-Jul-2004 07:31 |
| cookies, sessions? | skyloon | MySQL / PHP Forum | 1 | 10-May-2004 08:40 |
| Googlebot and sessions | JdS | Search Engine Optimization Forum | 0 | 26-Nov-2002 03:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The