Page 1 of 1

Need help for form code...

Posted: Fri Sep 15, 2006 8:16 am
by rawmessiah
Hi Guys

I'm very new to php wicth i've only just read from books want to set a php feedback page for my website but have it sent to my out look express. however i want to add a day date and time to my feedback page in the e-mail so when the e-mail comes in it will show there user id time country and so would also like to add to radio buttons o my feedback page. can someone help us out done most of the work but don't no the coding for the rest of it

Regars
mike from the Land down under...

Code: Select all

<?php
if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( 'init.php' );
}

$cmd = $_POST['cmd'];
if ( $cmd == 'posted' ){

	$txtname = trim($_POST['txttitle']);
	$txte-mail Address: = trim($_POST['txtname']);
	$txtphone number = trim($_POST['txtemail']);
	$txtcountry = trim($_POST['txtcountry']);
        $txtdepartment = trim($_POST['txtcountry']);
	$txttopic = trim($_POST['txtcomments']);

	$From    = $config['admin_email'];
	$To      = $config['feedback_email'];
	$Subject = str_replace('SITENAME',$config['site_name'],get_lang('email_feedback_subject'));


	$message = get_lang('feedback@somesite.com', MAIL_FORMAT);
	$message = str_replace('#txtname#',$txttitle,$message);
	$message = str_replace('#txtemail address#', $txtname,$message);
	$message = str_replace('#txtphone number#',$txtemail,$message);
	$message = str_replace('#txtcountry#', $lang['countries'][$txtcountry],$message);
	$message = str_replace('#txtdepartment#', $txtoffice, $message);
	$message = str_replace('#SITENAME#',$config['http://www.somesite.com'],$message);

	$success= mailSender($From, $To, $To, $Subject, $message);

	$t->assign( 'success', $success );
}

$t->assign('rendered_page', $t->fetch('feedback.tpl') );

$t->display( 'index.tpl' );
exit;
?>

Posted: Thu Sep 21, 2006 3:50 am
by Benjamin
Hi Mike,

have a look at the date function here.. http://php.net/date There are some pretty good examples there.

Radio buttons are easy as well..

Code: Select all

<input type="radio" name="thisOption" value="1" />
<input type="radio" name="thisOption" value="2" />
<input type="radio" name="thisOption" value="3" />
<input type="radio" name="thisOption" value="4" />

Posted: Thu Sep 21, 2006 5:11 am
by impulse()
You should use

Code: Select all

$date = getdate();
That creates an array in $data with seconds, minutes, hour, day etc etc.

Then I use sprintf to store the parts of the array I want to keep


Code: Select all

$datePrint = sprintf("%02d-%02d-%04d", $date['mday'], $date['mon'], $date['year']);
mday is the day of the month eg 10 and the rest explains itsself. If I echo $datePrint now it will output a nicely formatted date.

Regards,

Posted: Thu Sep 21, 2006 5:30 am
by CoderGoblin
When creating your radio buttons you can use:

Code: Select all

// build the option list (I normally place this near the top of the file
$radio_values=('Option1','Option2','$Option3','$Option4'); 

// Check if value exists in case form failed and reshowing the form (Validation of form values entered by user)
$radio_cur=(!empty($_POST['thisOption']) ? $_POST['thisOption'] : ''); 

// Step through the option list and output adding the 'checked' flag if necessary
foreach ($radio_values as $value) { // Step through the option list
  echo("<input type=\"radio\" name=\"thisOption\" value=\"$value\"".($value==$radio_cur ? '  checked' : '')." />\n"); 
}
OK you could just output the HTML itself without a loop but if you are checking for existing information for radio or checkbox items when a form fails, you might find the code above useful.