Not working drop down validation - codeigniter

I am trying to validate drop down but my code is not working.
View:
<tr>
<td width="10%"><?php echo form_label('Countryt Name:', 'countryname'); ?></td>
<td width="90%"><?php $country_namearray=array();
$country_namearray[]="Select";
foreach($country_name as $country){
$country_namearray[$country['id']]=$country['country_name'];
}
echo form_dropdown('country_id', $country_namearray,#$statedata[0]->country_id,'class="input-small" id="country_id" required="required" title="The Country Name field is required." autofocus="autofocus"'); ?>
</td>
</tr>
Controller:
$this->form_validation->set_rules('country_id', 'Country Name', 'trim|required|xss_clean');
What is problem in my code?

i checked your code and it seems that you need to edit your select item with empty value.
for ex:
$country_namearray[''] = 'Please Select';
hope this will solve the validation problem. if you dont provide any value it will convert it as 0. thats why your validation code werent working

Related

Request tracker REST API: Web Interface to Create New Tickets

I previously had a custom form that users could fill out to place work orders, and once they hit submit, it would create a new ticket with all the information and add it to one of the RT queues.
We previously used Mason to do this, but now we've moved to WordPress and would like to redo this in a cleaner way using PHP.
I read through the API documentation and reviewed this thread along with many others posted on Stack Overflow. I know how to connect to RT and create new tickets via command line and cURL, but I can't seem to figure out how to do so using the web interface on submit. I would really appreciate if someone could give me some pointers on where to start.
Thanks
Edit:
Thank you for the response. Below is the form I've made which interacts with a our SQL database to pull some information and I need it to create a new ticket with all the information on submit. Should I create a new php file similar to [this][2] and include it as a form action?
<form action="<?php echo $_SELF; ?>";
method="post"
id="woForm"
name="woForm"
enctype="multipart/form-data"
>
<input type="hidden" name="session_id" value="<?php echo session_id(); ?>">
<input type="hidden" name="Queue" value="<?php echo $queue; ?>">
<input type="hidden" name="id" value="new">
<input type="hidden" name="Status" value="new">
<input type="hidden" name="Owner" value="10">
<table width="450" align="center" border="0" cellpadding="0" cellspacing="5">
<tr><td align="left" colspan="2">
<h2><?php echo $name; ?></h2>
<p>Please note that all fields except for <b>Ext:</b>, <b>CC:</b> and <b>Attachments:</b> are <span class="required">required</span>.
You cannot submit a request for assistance using this form unless all the required
fields have been completed.</p>
<h2 style="color:red;">Please enter information for the INDIVIDUAL needing assistance</h2>
</td>
</tr>
<?php
// Get all of the customFields
$query1 = "select * from CustomFields where disabled='0' and sortOrder != 0 order by sortOrder ASC;";
$result1 = mysql_query($query1) or die ("dead3: ".mysql_error());
// Go through each custom field
while($row1 = mysql_fetch_array($result1)) {
// Get the information about that field
$count = 0;
$fieldId = $row1['id'];
$name = $row1['Name'];
// $postname is in a very specific format, and will become the name of the field in the form
// where the data for this custom field is entered. In order to submit a ticket into rt, the
// name of the field MUST be in this format.
$postName = "Object-RT::Ticket--CustomField-".$fieldId."-Values";
?>
<!-- Create a row in the table for this custom field -->
<tr>
<!-- Create a column with the name of the custom field -->
<td align="right" class="requestformlabel"><label class="required"><?php echo $name; ?>:</label></td>
<!-- Create a column for the input field -->
<td class = "requestformtd">
<?php
// If the custom field is department or building, we need a pull-down menu
if($name=="Department" || $name=="Building") { ?>
<!-- start of the pull-down menu -->
<select name="<?php echo $postName; ?>">
<?php
// Get all of the possible values for the customField from the database
// Added option to exclude sort order 9999. See ticket #40665 for more info.
$query3 = "SELECT * FROM CustomFieldValues WHERE CustomField='$fieldId' AND SortOrder != '9999' ORDER BY SortOrder ASC";
$result3 = mysql_query($query3) or die ("dead4: ".mysql_error());
// Go through each possible value for the custom field
while($row3 = mysql_fetch_array($result3)) {
// Get the information on the custom field value from the database
$tmp = $row3['Name'];
$description = $row3['Description'];
// If the custom field value was already selected
if($tmp == $_POST["$postName"]) {
// Insert the option into the pull-down menu and mark it as selected in the form
echo "<option value='$tmp' selected='selected'>$description</option>";
// otherwise
} else {
// Only insert it as an option in the pull-down menu
echo "<option value='$tmp'>$description</option>";
}
}
?>
</td></tr>
<?php
// If the name of the custom field is operating system, we want radio buttons
} else if ($name == "Operating System") {
// Get all the possible values for this field form the database
$query4 = "select * from CustomFieldValues where CustomField='$fieldId' order by sortorder asc";
$result4 = mysql_query($query4) or die ("dead5: ".mysql_error());
// For each customfield value
while($row4 = mysql_fetch_array($result4)) {
// Get the description of the customfieldvalue from the database
$osName = $row4['Description'];
// If the customfieldvalue has already been selected
if ($osName == $_POST["$postName"]) {
// Put the radio button into the form and mark it as checked
echo "<input type='radio' name='$postName' value='$osName' checked='checked'>$osName";
// Otherwise
} else {
// Put the radio button into the form
echo "<input type='radio' name='$postName' value='$osName'>$osName";
}
} ?>
</td></tr>
<?php
// If the name of the custom field is ip adress, we want a disbaled text box. This is because while we want the user to see their ip adress, we do not want them to be able to change it.
} else if ($name == "IP_Address"){
?>
<input name="<?php echo $postName; ?>" size="40" value='<?php
echo $_SERVER['REMOTE_ADDR']; ?>' readonly></td></tr>
<?php
// If it's the hostname variable
} else if ($name == "Host_Name"){
?>
<input name="<?php echo $postName; ?>" size="40" value='<?php echo gethostbyaddr($_SERVER['REMOTE_ADDR']); ?>' readonly></td></tr>
<?php
// Otherwise, create a text box for the custom field.
} else {
?>
<input name="<?php echo $postName; ?>" size="40" value='<?php echo $_POST["$postName"]; ?>'></td></tr>
<?php } // end else statement
} // end while loop
?>
<tr>
<td class="requestformlabel" align="right"><label class="required">Your E-mail Address:</label></td>
<td align="left" class="requestformtd"><input name="Requestors" size=40 value="<?php echo $_POST['Requestors']; ?>"></td>
</tr>
<tr>
<td class="requestformlabel" align="right"><label class="required">Confirm Your E-mail Address:</label></td>
<td align="left" class="requestformtd"><input name="Requestors_2" size=40 value="<?php echo $_POST['Requestors_2']; ?>"></td>
</tr>
<tr>
<td class="requestformlabel" align="right"><label class="fields">Cc:</label></td>
<td align="left" class="requestformtd"><input name="Cc" size=40 value="<?php echo $_POST['Cc']; ?>"></td>
</tr>
<tr>
<td align="right"><p> <br/> </p></td>
<td align="right"><span class="ccnote">(Separate multiple email addresses with commas.)<br/> </span></td>
</tr>
<tr>
<td class="requestformlabel" align="right"><label class="required">Short Problem Summary:</label></td>
<td align="left" class="requestformtd"><input name="Subject" size=40 maxsize=100 value="<?php echo $_POST['Subject']; ?>"></td></tr>
<tr>
<td class="requestformlabel" align="right"><label class="required">Decribe the issue below:</label></td>
<td align="left" class="requestformtd"><textarea
class="messagebox" cols=35 rows=15 wrap="hard" name="Content"><?php echo $_POST['Content']; ?></textarea>
</td>
</tr>
<?php
//if session has attachments
if($_SESSION['attach'] != '') {
?>
<!-- row for existing attahcments -->
<tr>
<!-- column that states these are the current attachments, and tells the user what to do if
they wish to remove an attachment. -->
<td class="requestformlabel" align="right">Current Attachments:<br/>
<span class="ccnote">(Check box to delete)</span>
</td>
<!-- coulmn that lists the attachments -->
<td class="requestformtd" align="right">
<?php
// Go through each file in $_SESSION['attach']
while (list($key, $val) = each($_SESSION['attach'])) {
// Get the name of the file
$attName = $val['name'];
// Create a checkbox to mark the file as needing to be removed from the list
echo "<input type='checkbox' name='DeleteAttach-$attName' value='1'>$attName<br/>";
} // end while loop
?>
</td>
</tr>
<?php // end if for attachments
}
?>
<tr>
<td class="requestformlabel" align="right"><label class="fields">Attachments:</label></br>
<span class="ccnote">Max. attachment size: 50MB.</span></td>
<td align="right" colspan="2" class="requestformtd">
<input type="file" name="Attach">
<br/>
<input type="submit" name="AddMoreAttach" value="Add More Files">
</td>
</tr>
<tr>
<td align="left"><input type="submit" name="submit" value="Submit Request"></td>
<td> </td>
</tr>
</table>
</form>
Edit 2:
Thanks. Using the documentation and code from this repo I created a new file called new_ticket.php with the following content:
<?php
if($_POST['action'] == 'call_this') {
require_once 'RequestTracker.php';
$url = "www.test.com/rt/REST/1.0/";
$user = "user";
$pass = "password";
$rt = new RequestTracker($url, $user, $pass);
$content = array(
'Queue'=>'9',
'Requestor'=>'test#example.com',
'Subject'=>'Lorem Ipsum',
'Text'=>'dolor sit amet'
);
$response = $rt->createTicket($content);
print_r($response);
}
?>
I also made of copy of RequestTracker.php from the same Github repo.
In the file where the form is located, I added the following script and added create_ticket() as an action to the onclick property of submit button. But this doesn't seem to be working. I tried logging something to the console to see how far the code gets, the create_ticket() function is being called properly but anything that comes after $.ajax({ ... above will not appear to the console. I also tried putting some console logs in my new_ticket.php file but that doesn't log anything either, so what am I doing wrong?
<script>
function create_ticket() {
$.ajax({
url:"new_ticket.php", //the page containing php script
type: "POST", //request type
data:{action:'call_this'},
success:function(result){
alert(result);
}
});
}
</script>
PS: I'm using ajax because I need to run the PHP code onclick and this can't be done directly as it would in Javascript.
Probably the easiest approach is to look at the PHP examples in the REST documentation on the Request Tracker wiki. You don't mention the version of RT you are using, but the REST interface has been stable so this should work with most versions.

Adding a Logon message to pages

I'm looking to create a log in feature every time users go to various members only pages, which returns them to the original page after logging in. I've seen various answers to this question but none of them seem to include a check feature followed by a return to the original page. At the moment the code I have created doesn't seem to recognize that I have logged in and keeps returning me to the log in form. Any answers will be greatly appreciated. I realize I am using deprecated code but that is the only version my host provider's servers recognize.
Here's the code I am putting at the top of each members page
<?php
session_start();
if($_SESSION['login'] != "yes" )
{
header("Location: main_login.php");
exit();
}
?>
This then opens the main_login.php page
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
On clicking the login button the following code in checklogin.php checks the entries
<?php
$host='.....'; // Host name
$username='.....'; // Mysql username
$password='........'; // Mysql password
$db_name='....'; // Database name
$tbl_name='......'; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_start();
$_SESSION['myusername'];
$_SESSION['mypassword'];
header("location:entry_form_european_languages.php");
}
else {
echo "Wrong Username or Password";
}
?>
The last header location refers to the page I would like to return to, which seems to the repeat the process of opening up the login and check in files- as if to indicate that the return page doesn't recognize that the log in was successful.
I would need to add something that was relative to each page, but since I don't know where I am going wrong with the fixed page return, I can't move on to that stage of coding.
I did have an alternative header address which took it to the following page login_success.php which gave the impression that username entries had been accepted, but this doesn't allow me to return to the original page
<?php
session_start();
if(isset($_SESSION[$myusername])){
header("Location:entry_form_european_languages.php");
}
?>
<?php
include '........';//Formatting for the page
?>
<html>
<body>
Login Successful
</body>
</html>
Thanks in advance.
There are a few extra things I needed to add to make the session details work, as follows. This code needs to go ahead of any other code on the page including any html code that relates to character formatting. Although I have coded it out the error reporting line is handy for indicating which line is not being read by the php server, should you have continued problems.
<?php
//error_reporting(E_ALL); ini_set('display_errors', 'On');
session_start();
ob_start();
if(!isset($_SESSION['myusername'])){
header('Location:main_login.php');
}
else if (isset($_SESSION['myusername'])){
}
$myusername=$_SESSION['myusername'];
$Page_Title ='Members Profile';
?>

Adding product description , product image etc in custom Transactional Email for New order

I have created a new custom template using the New order default template in my Magento admin panel.
There are some default variables available to be inserted into the email. But I want to add some other variables like product description into the email template.
In my email after order creation , I want to send description and other details of all products that are present in my cart.
What I have in template is :
<table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<img src="xyz.jpg"/>
</td>
</tr>
<tr>
<td>
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId("{{var order.increment_id}}");
$items = $order->getAllVisibleItems();
foreach($items as $i):
echo $i->getProductId();
echo $i->getDescription();
echo $i->getDescription();
endforeach;
?>
</td>
</tr>
I want to achieve something like this. Is it possible adding PHP code into the email template and get the variables working. Or I have to define this php code somewhere else? If yes, can you please specify where to make these changes?
Thanks
I dont think u need to load product object in email template it is already loaded if not u can do that but sure u dont need sales order object that sure.
app\design\frontend\default\imsov2\template\email\order\items\order\default.phtml
<?php echo $this->escapeHtml($_item->getDescription()) ?>
and so on...

Watir Display Content from a table in a text file

I am using watir-webdriver, I am trying to write the content displayed in a table below (RATE CODE SELECTED NOT AVAILABLE THIS LOCATION OR CAR 138DE) into a text file but I can't get it to display the content. Any idea what i doing wrong ? Thanks in advance for your help.
errorMes = browser.select_list(:name => 'seamlessMessages').value
f3=File.open( 'Error Log - Conf Res.txt', 'a')
f3.puts "Cancel Reservation - FAILED - Res ID: " +tasid+" - " + CSAsite + " - Message: " +errorMes
f3.puts "\n"
f3.close
code
<TD><B>Error/Informational Messages</B></TD>
<TD><B>Number of Messages</B></TD>
<TD class="tableData"><span name="nbrOfMessages"/>1</span></TD>
<TD> </TD>
</TR>
<TR>
<TD height="1"></TD>
</TR>
</TABLE>
<TABLE width="100%" class="displaySubsection" cellpadding="0" cellspacing="0">
<TR>
<TD width="5" rowspan="3"></TD>
<TD width="800"></TD>
<TD width="5" rowspan="3"></TD>
</TR>
<TR>
<TD>
<select name="seamlessMessages" size="2" readonly tabIndex="-1" class="readonly wide"><option value="0" selected>RATE CODE SELECTED NOT AVAILABLE THIS LOCATION OR CAR 138DE </option></select>
</TD>
I assume your problem is that you are getting "0" instead of "RATE CODE SELECTED NOT AVAILABLE THIS LOCATION OR CAR 138DE".
When you do errorMes = browser.select_list(:name => 'seamlessMessages').value, it is returning the 'value' attribute of the selected option.
If you want the text, you need to do:
errorMes = browser.select_list(:name => 'seamlessMessages').selected_options.first.text
Yes you're right I was getting "0"
Just to let you know that when i tried
errorMes = browser.select_list(:name => 'seamlessMessages').selected_options.first.text
I got an error message in <main>': undefined methodtext' for "RATE CODE SELECTED
NOT AVAILABLE THIS LOCATION OR CAR 138DE":String (NoMethodError)
By removing .text it did work. Thanks a lot for your help on this.
errorMes = browser.select_list(:name => 'seamlessMessages').selected_options.first

Adding a 'add another' option in Wordpress custom meta box using jquery $.post

I'm creating a wordpress plugin, with a custom post type and in that post type a custom meta box.
Inside the meta box, I have a form that let's the user input: Date, Media, Title.
The form looks like this:
$mc_date = get_post_meta($_GET['post'],'mc_date',true);
$mc_media = get_post_meta($_GET['post'],'mc_media',true);
$mc_title = get_post_meta($_GET['post'],'mc_title',true);
echo '<form id="add_media_form">';
echo '<table>';
echo '<tr>';
echo '<td>Date</td><td>Media</td><td>Title</td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="text" name="mc_date" value="'.$mc_date.'" class="datepicker"/></td>';
echo '<td><input type="text" name="mc_media" value="'.$mc_media.'" /></td>';
echo '<td><input type="text" name="mc_title" value="'.$mc_title.'" /></td>';
echo '<td><img src="'.WP_PLUGIN_URL.'/mc/plus.png" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '<div class="addmedianotify"></div>';
jquery:
jQuery('.add_new_media').click(function(e){
var plug = jQuery(this).attr('rel');
e.preventDefault();
jQuery.post(plug + '/ajax_add_media.php',jQuery('#add_media_form').serialize(),function(data){
jQuery('.addmedianotify').html('<span>'+data+'</span>');
});
});
What I want to do, is that when the user click the 'add_new_media' link/image a new set of textboxes for date, media and title will appear.
My main concern is that, what's the trick to name those inputs which is dynamic. and to save and retrieves the custom data in it.
Because the page will still update when the user clicks 'Update' you would need to be able to save your fields on save_post and in your ajax. Using ajax for this might not be the best method as you're making more work for yourself by needing to save that data twice. I would ditch the ajax and simply use an html array so you can add on fields and make one submission when the user clicks 'Update'. To add new rows as the user needs, I would simply clone your tr and append it to the table in your click event. Something like...
The PHP & HTML
<img src="'.WP_PLUGIN_URL.'/mc/plus.png" />
<table>
<tr>
<td>Date</td>
<td>Media</td>
<td>Title</td>
<td></td>
</tr>
<?php
//$mcs will be a multi-dimensional array with this method
$mcs = get_post_meta($post->ID,'mcs',true);
//Loop through each set of saved mc data (date, media, and title per item) and output inputs so the saved values can be edited and resaved.
foreach ($mcs as $mc) : ?>
<tr>
<td><input type="text" name="mc[][date]" value="<?php echo $mc['date'] ?>" class="datepicker"/></td>
<td><input type="text" name="mc[][media]" value="<?php echo $mc['media'] ?>" /></td>
<td><input type="text" name="mc[][title]" value="<?php echo $mc['title'] ?>" /></td>
<td>Remove</td>
</tr>
<?php endforeach ?>
</table>
The Javascript
<script>
(function($){
//Grab the first
$('.add_new_media').click(function(e) {
//Use the first tr as a cookiecutter and add another cookie to the bowl :)
$('table tr:first-child')
.clone()
.appendTo($('table'))
.find('input')
.val('')
}
$('.remove').click(function(){
$(this).parent().parent().remove()
})
})(jQuery)
</script>
The PHP upon form submission
<?php
if ($_POST) :
//$_POST['mc'] is a multi-dimensional array of all the date/media/title input rows
print_r($_POST['mc']);
/*
..would look something like
Array (
[0] => Array (
'date' => 'some value',
'media' => 'some value',
'title' => 'some value'
),
[1] => Array ( ... ),
[2] => Array ( ... ) ... and so on
)
*/
//RUN INPUT VALIDATION!!
//Update the list
update_post_meta($post->ID, 'mcs', $_POST['mc']);
endif;
?>

Resources