Let's go ahead and get the carrier. We'll set it up so that if Joe Enduser decides that he does not choose to opt-in for SMS messages, he'll not be bothered with choosing a carrier.
Lets start out by understanding that you CAN have HTML code in a .PHP page, but not PHP code in an .HTML page. Also, we'll need to understand that javascript requires basic HTML page structure to operate properly, even if it's in a .php page. That being said, let's open up
include/client/open.inc.php
At the very top of the page (Line 1) add this code...
function disableText()
{
if(document.myform.optin.checked){
document.myform.cell.disabled=false;
document.myform.carrier.disabled=false;
}else{
document.myform.cell.disabled=true;
document.myform.carrier.disabled=true;
}}
We start off with so that we will have proper HTML structure for the javascript that follows. Then we create a function that manipulates the elements of the form. We'll say IF the optin box is checked, the cell field and the carrier field will become active. Otherwise they will stay disabled, and not bother Mr. Enduser.
Let's go down to line 57, it looks like this...
<form action="open.php" method="POST" enctype="multipart/form-data">
We can't manipulate a form without a name, replace line 57 with this code...
<form name="myform" action="open.php" method="POST" enctype="multipart/form-data">
Remember earlier when we added the optin and cell fields? We'll need to make a few small modifications to those fields and add in our carrier select.
Find the two fields you added earlier, make the code look like this.....
<tr>
<th>Recieve SMS Notify?:</th>
<td><input type="checkbox" id="optin" name="optin" value="1" onclick="disableText();" >
<font class="error"> <?=$errors?></font>
</td>
</tr>
<tr>
<th>Cell Phone:</th>
<td><input type="text" id="cell" name="cell" size="25" value="<?=$info?>" disabled>
<font class="error"> <?=$errors?></font>
</td>
</tr>
<tr>
<th>Carrier:</th>
<td>
<select name="carrier" id="carrier" disabled>
<option value="@vtext.com">Verizon</option>
<option value="@tmomail.net ">T-Mobile</option>
<option value="@messaging.sprintpcs.com">Sprint</option>
<option value="@txt.att.net">AT&T</option>
<option value="@vmobl.com">Virgin Mobile</option>
<option value="@message.alltel.com">Alltel</option>
<option value="@sms.mycricket.com">Cricket</option>
</select>
</td>
</tr>
Don't forget, at the very bottom of the page we need...
</body>
</html>
to complete our HTML page structure.
And we are done with include/client/open.inc.php
Were going to need another space in the database to store the carrier. Go back to PHPMyAdmin and run this query..
ALTER TABLE ost_ticket ADD column carrier varchar(30);
Now let's make the necessary modifications so that we get the carrier from the field and write it to the database in...
class.ticket.php
Find this code that we added earlier...
var $cell;
var $optin;
add this code below it...
var $carrier;
Find this code that we added earlier...
$this->cell =$row;
$this->optin =$row;
add this code below it...
$this->carrier =$row;
Find this code that we added earlier...
function getCell(){
return $this->row;;
}
function getOptin(){
return $this->optin;
}
add this code below it...
function getCarrier(){
return $this->carrier;
}
Find this code that we added earlier...
$fields = array('type'=>'phone', 'required'=>0, 'error'=>'Cell required');
$fields = array('type'=>'int', 'required'=>0, 'error'=>'Optin required');
add this code below it...
$fields = array('type'=>'string', 'required'=>0, 'error'=>'Carrier required');
Find this block of code....
if(!$errors){
$sql='UPDATE '.TICKET_TABLE.' SET updated=NOW() '.
',email='.db_input($var).
',name='.db_input(Format:($var)).
',referer='.db_input(Format:($var)).
',cell="'.db_input($var,false).'"'.
',optin='.db_input($var).
add this code below it....
',carrier='.db_input($var).
Find this block of code...
$id=0;
$fields=array();
$fields = array('type'=>'string', 'required'=>1, 'error'=>'Name required');
$fields = array('type'=>'string', 'required'=>0, 'error'=>'Referer required');
$fields = array('type'=>'phone', 'required'=>0, 'error'=>'Cell required');
$fields = array('type'=>'int', 'required'=>0, 'error'=>'Optin required');
add this code below it...
$fields = array('type'=>'string', 'required'=>0, 'error'=>'Carrier required');
Find this code that we added earlier...(Around line 1364)
',cell="'.db_input($var,false).'"'.
',optin='.db_input($var).
below it add this code...
',carrier='.db_input($var).
Now we have opt-in value controlling the availability of cell and carrier; and all values being saved to the database.