Recommend this page to a friend! |
|
![]() Hi,
I am using the form_date plugin with the following php: $form->AddInput(array( "TYPE"=>"custom", "NAME"=>"recontact_date", "ID"=>"recontact_date", "LABEL"=>"Recontact <u>D</u>ate", "ACCESSKEY"=>"D", "CustomClass"=>"form_date_class", "VALUE"=>$today, "Format"=>"{day}/{month}/{year}", "Months"=>array( "01"=>"January", "02"=>"February", "03"=>"March", "04"=>"April", "05"=>"May", "06"=>"June", "07"=>"July", "08"=>"August", "09"=>"September", "10"=>"October", "11"=>"November", "12"=>"December" ), "Optional"=>1, "ValidationStartDate"=>$start_date, "ValidationStartDateErrorMessage"=>"A Recontact date before the today was specified." )); After I submit my form the date which is displayed on the confirmation field is in this form: 14/January/2012. I insert a row in MySQL with the query: INSERT INTO project VALUES (...,'$recontact_date',...) where the "recontact_date" field is a DATE field in the MySQL database. Whatever I try this field seems to return 0000-00-00. I have tried changing the name "recontact_date" to "date". I have tried using a numeric field in the SQL statement, i.e. $recontact_date rather than '$recontact_date'. I have tried mapping "01"=>"01","02"=>"02, etc. in order to get rid of the textual month name in the confirmation page. All without result. Can you spot what I am doing wrong, as I'm sure it is quite simple and I have been spending hours on it. Regards, Geoff.
![]() This does not seem to be related with the forms class.
You do not seem to be executing an INSERT query with the names of the fields, only the values. I suspect that the table field order is no the same that you assume. I recommend that you always pass the name of the fields explicitly.
![]() Hi Manuel, Thanks for the quick response. I don't think that the query is the problem. I previously had the field as a simple text field and it inserted correctly in the exact same query.
![]() Well, the query may or not may be not causing your problem. Regardless of that you should fix the query and add the list of fields explicitly, because it is a recommended good programming practice, first to clear the doubt that is the reason for your problem or not, and second, even it is not the reason it may prevent getting you into future bugs when you change the table for some reason.
Anyway, the AddInput function returns a non-empty string in case you are passing inconsistent values that may prevent the field to be correctly added to the form, like for instance the VALUE parameters being in the wrong format. Try checking if the return value of the AddInput function to see if it is an error message. Other than that you are not telling how you are retrieving the value of the date input to use in the query, so it is not possible to me to figure if you are not doing it right.
![]() I have put in the field list explicitly, as you recommend. I can see how that is good practice. However, as I suspected it did not solve the problem.
Sorry if I did not give sufficient information. I use the standard method for forms generation, I call the template as below: _________________________________________________________________ <?php /* * Compose the form output by including a HTML form template with PHP code * interleaaved with calls to insert form input field * parts in the layout HTML. */ $form->StartLayoutCapture(); $title="Add Project"; $body_template="project_body.html.php"; require("templates/form_frame.html.php"); $form->EndLayoutCapture(); /* * Output the form using the function named Output. */ $form->DisplayOutput(); ?> _________________________________________________________________ This is the relevant section in the template "project_body.html.php": _________________________________________________________________ ... <tr> <th align="right"> <?php $form->AddLabelPart(array("FOR"=>"recontact_date")); ?>:</th> <td><?php $form->AddInputPart("recontact_date"); ?></td> <td><?php echo (IsSet($verify["recontact_date"]) ? "[Verify]" : ""); ?></td> </tr> ... _________________________________________________________________ I then get all the posted fields as follows: _________________________________________________________________ mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); //$refno=$_POST['refno']; $cust_code=$_POST['cust_code']; $name=$_POST['name']; $type=$_POST['type']; $value=$_POST['value']; $schedule=$_POST['schedule']; $lead_status=$_POST['lead_status']; $open_status=$_POST['open_status']; $closed_status=$_POST['closed_status']; $rep_code=$_POST['rep_code']; $recontact_date=$_POST['recontact_date']; $conv_pottl=$_POST['conv_pottl']; $active=$_POST['active']; $gps_north=$_POST['gps_north']; $gps_west=$_POST['gps_west']; $comment=$_POST['comment']; $date_created=date("Y-m-d"); $date_updated=date("Y-m-d"); $date_closed=$_POST['date_closed']; $comment=str_replace("'", "'", $comment); $gps_north=str_replace("'", "'", $gps_north); $site_address=str_replace("'", "'", $site_address); @mysql_select_db($database) or die( "Unable to select database"); //Escape any random rubbish $comment = mysql_real_escape_string($comment); $lead_status = mysql_real_escape_string($lead_status); $open_status = mysql_real_escape_string($open_status); $closed_status = mysql_real_escape_string($closed_status); $conv_pottl = mysql_real_escape_string($conv_pottl); $gps_north = mysql_real_escape_string($gps_north); $gps_west = mysql_real_escape_string($gps_west); $query = "INSERT INTO project (code, refno, cust_code, name, type, value, schedule, lead_status, open_status, closed_status, rep_code, recontact_date, conv_pottl, active, gps_north, gps_west, comment, date_created, date_updated, date_closed) VALUES ('','$refno',$cust_code,'$name','$type',$value,'$schedule','$lead_status','$open_status','$closed_status',$rep_code,'$recontact_date','$conv_pottl',$active,'$gps_north','$gps_west','$comment','$date_created','','')"; do_query($query,__LINE__); _________________________________________________________________ Regards, Geoff.
![]() Still no joy with this! The return value, as I said above, is in the form 14/January/2012. I am worried that the month shows as January rather than 01. Is this because of the "Optional" field being set to 1?
![]() The problem is that you are using the $_POST values directly and that will not work because the form date input is in reality made of several inputs.
You need to use the GetInputValue function instead to get the correct value. Furthermore, if you use $_POST instead of GetInputValue, you risk yourself making your applications subject of security exploits as the forms class in some cases cleans or discard invalid values that could be used to perform for instance SQL injections. So always use GetInputValue to get secured form input values.
![]() Thanks very much for your help! That was the problem. I didn't realize that GetInputValue was necessary. It is my first attempt at using this class.
|
info at phpclasses dot org
.