kosta_g Posted October 19, 2010 Share Posted October 19, 2010 hey all, I've hit a little bit of a brick wall and the tyres just keep on spinning :-) My issue is this, I have a form which is really kinda basic. It relies on user input, and has both server and client side validation, the client side being done with PHP. I have never worked with both and it was a stretch trying to do both at the same time but finally it's working. This is the script for the actual PHP validation which works: <?php include ('form/formvalidator.inc'); $form = new formValidator('change_of_number'); $form -> minimumlength('user',3,'Username must have at least 3 characters !'); $form -> notEmpty('cnumber','You forgot to enter a Customer Number !'); $form -> minimumlength('cnumber',7,'Customer number must be 7 characters !'); $form -> validateNumber('cnumber','Customer Number must only contain numbers !'); $form -> notEmpty('snumber','You forgot to enter a Service Number !'); $form -> minimumlength('snumber',10,'Service number must be 10 characters !'); $form -> validateNumber('snumber','Service Number must only contain numbers !'); $form -> notEmpty('altnumber','You forgot to enter a Contact Number !'); $form -> minimumlength('altnumber',10,'Contact Number must be 10 characters !'); $form -> validateNumber('altnumber','Contact Number must only contain numbers !'); $form -> notEmpty('custname','You forgot to enter the Customer Name !'); $form -> notEmpty('con_reason','Please select Reason for Change of Number !'); $form -> notEmpty('silent_number','Please advise if New Number is Silent !'); $form -> setColor('#FF0000'); $validation_js_code = $form -> parse(); if ( $form -> valid() === true ) { //this is what happens when the form validates successfully echo '<b>Form has been successfully submitted !</b>'; } else if ( $form -> valid() ) { $error_message = '<b style="color:red;">'.$form -> valid().'</b>'; //if there is an error $form -> valid() returns the error message; } ?> I now have in a seperate file, the mailing script, which works fine on it's own without an issue and sends a HTML based response back to the user. <?php //define the receiver of the email $to = 'user@domain.com.au'; //define the subject of the email $subject = 'User Request : Change of Number for:'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: kgkekas@primustel.com.au\r\nReply-To: kgkekas@primustel.com.au"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <style type="text/css"> <!-- .style1 { font-family: Arial, Helvetica, sans-serif; font-size: large; font-weight: bold; font-style: italic; color: #666666; } --> </style> <h2><b><img src="http://centari/joomla/shared/cons_forms/mail_test/label_blue_new.png" width="128" height="128" align="middle"><font face="Arial, Helvetica, sans-serif" size="+3">Change of Number Receipt- (Optus) </font></b></h2> <h2>Hello Team!</h2> <p>You have been sent a request by <?php //enter name of person who has logged the request ?>.</p> <p>Please action this <strong>Change of Number</strong> request for <?php echo test; ?>.</p> <table width="50%" border="0" cellspacing="5" cellpadding="5"> <tr> <th scope="col"> </th> <th scope="col">FORM REQUEST </th> </tr> <tr> <td><strong>Service Number : </strong></td> <td><?php echo 'test Service Number';?></td> </tr> <tr> <td><strong>Customer Name : </strong></td> <td><?php echo 'Test Customer Name';?></td> </tr> <tr> <td><strong>Contact Number : </strong></td> <td><?php echo 'Test Contact Number';?></td> </tr> <tr> <td><strong>Reason for Change of Number : </strong></td> <td><?php echo 'Test Change of Number Reason';?></td> </tr> <tr> <td><strong>New Number to be Silent : </strong></td> <td><?php echo 'New number silent';?></td> </tr> <tr> <td><strong>Comments : </strong></td> <td><?php echo 'test Comments';?></td> </tr> </table> <p> </p> --PHP-alt-<?php echo $random_hash; ?>-- <? //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> My question is this, how is it that i can tie the email script to the validation script? Im guessing i can add it after if ( $form -> valid() === true ) { //this is what happens when the form validates successfully echo '<b>Form has been successfully submitted !</b>'; } else if ( $form -> valid() ) { bhut not overly sure ... any help would be appreciated :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.