Jump to content

rwhite35

Members
  • Posts

    159
  • Joined

  • Last visited

Everything posted by rwhite35

  1. Regarding instantiating your $_POST variables, you might consider this technique. // convert $_POST array into scalar variables // example $_POST['practice_type'] = somestring // becomes $practice_type = somestring if(!empty($_POST)) { foreach($_POST as $key=>$value) { ${$key} = $value; } } // now process your variables a scalar vars You would use this in your first few line of code after you scrubbed the $_POST array. Regarding PEAR Mail, it optimizes your email and allows you to send multiple emails without having to call the mail function multiple times. So its safer and faster then mail function. PEAR Mail is part of the PHP distro since 5, if you can cd to your PHP binary, you should see a folder called Mail and a file called Mail.php. Hope that helps.
  2. Here is a JQuery/Javascript function I like to use: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { //client side field validation before submit processing var regexp = /^([A-Za-z0-9_\+\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; $("form").submit(function() { if ($("input:first").val()==''){ alert("You need a subject!"); return false; } else if ($('input[name="uname"]').val()==''){ alert ("You need a name!"); return false; } else if ($('input[name="uemail"]').val()=='' || ($('input[name="uemail"]').val().match(regexp)<1)){ alert ("You need a value email address"); return false; } else { //if valid, send data for server side processing //$.ajax({url:'lib/emailProcess.php',type:'post'}); alert("Your email was submitted"); return true; }; }); }); </script>
  3. Try setting up your headers this way: $headers['From'] = '[email protected]'; $headers['Reply-To'] = '[email protected]'; $headers['Subject'] = $_POST['subject']; Also I would consider using a mail framework like PEAR Mail. http://pear.php.net/package/Mail/redirected Here is the PEAR Mail implementation: /* -- PEAR::MAIL * PEAR::Mail only opens one mail socket */ require_once('/local/path/to/php/Mail.php'); //this would be the path to your PEAR Mail library $recipients = [string] or [array]; $headers['From'] = '[email protected]'; $headers['Reply-To'] = '[email protected]'; $headers['Subject'] = $_POST['subject']; $params['sendmail_path'] = '/usr/sbin/sendmail'; //using sendmail on backend $mail_object =& Mail::factory('sendmail',$params); //using factory method Then you call the class and send the mail //send the mail instance $mail_object->send($recipients,$headers,$email_message); if (PEAR::isError($mail_object)) {print($mail_object->getMessage());} FInally, I would move the form validation to the client side using JQuery and Javascript. You would still scrub the input like you have it or you could also use one of PHP's build in function.
  4. At the risk of stating the obvious, I'll assume you have included you javascript up in the head with something like: <script src="gen_validatorv4.js" type="text/javascript"></script> Your form needs an id, something like <form action='' method="post" id="myform"> Then you call your class with: var frmvalidator = new Validator("myform"); And as was stated above, this is client-side validation, you'll still need to scrub your input on the server-side, and that's where the PHP will come in handy. Good luck,
  5. exeTrix, thanks for the reply. I like your algorithm MUCH better. Nice And Clean! Unfortunately, I get the same result. I like simpleXML and use it to output xml to the browser window, however, when I need to manipulate the xml, I'm forced in to domdocument. As you already know, domdocument isn't well documented... or widely used. Here is potentially a clue to the problem, preservewhitespace=false is only removing white space when deleting parent nodes (blog) at the beginning or at the end of the XML. But never when the nodes are inbetween the first or last parent. And to your point, it seems like the there are two sets of objects being manipulated when only $tempxml should be the one processed. Final comment, I've tried hard coding $pid and also assigning it from form input, I'm pretty sure $pid is not the issue. I think this may be a bug with the DOMDocument class. Thanks again for the assist!
  6. Hi first time poster. I have a PHP/XML blog app and want to give users the ability to delete multiple blog post, with one form submit. The solution is working when blog post ids are not in order. That is if post id selected was 2 and 4, both nodes are deleted from the xml tree. But if the post id selected were 1 and 2, only 2 would be deleted. Has anybody else come across this behavior? Here's some code: psuedo xml <root> <blog id=1><copy>Some copy here</copy></blog> <blog id=2><copy>More copy</copy></blog> <blog id=3><copy>Even more copy</copy></blog> <blog id=4><copy>Last copy</copy></blog> </root> PHP, this is a method in a larger class /** * method usage: $objVar->deletePost($param) * delete client selected xml[blog] entries * @param array, $params : assign $_POST array as argument * @return string, XML */ public function deletePost($params) { foreach ($params as $value){ // assign multi-dim $param[delete][n] to two-dim array $pid=$value; // $value looks like array([0]=>[n],[1]=>[n]) } $xml = new DOMDocument(); // instance of current xml $xml->load($this->fp); // path to file $xml->preserveWhiteSpace = false; //define xpath object, called with query() line 273 $xpath = new DOMXpath($xml); //create temporary DOM xml $tempxml = $xml->documentElement; $pnode = $xml->getElementsByTagName('blog'); foreach($pnode as $key){ //outter loop thru parent nodes foreach($pid as $v){ //inner loop thru pid array if ($key->getAttribute('id')==$v){ //if pid matches blog[id=n] $path = "//root/blog[@id=".$v."]"; $nodelist = $xpath->query($path); $removenode = $nodelist->item(0); //remove the parent/children for matching ids $oldxml = $tempxml->removeChild($removenode); } } } echo $xml->saveXML(); } Thanks in advance, rwhite35
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.