Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'form'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 13 results

  1. I believe I found an error in the digital online copy. It is in Chapter 2 under "Handling an HTML Form". Paragraph 3 reads: PHP is case-sensitive when it comes to variable names, so $_REQUEST[‘city’] will work, but $_REQUEST[‘city’] and $_REQUEST[‘city’] will have no value. I'm not seeing any difference in the three variable names. I believe this sentence needs to be fixed.
  2. Hello, I want a form that create a "Feuille de jour" based on dropdownlist from other models. In fact, I have 4 tables that are linked by id : the table "Feuille de jour" have the id from the tables "poste FDJ", "categorie FDJ" and "personnel". When I create a "Feuille de jour", I want to be able to select (in a dropdown list) the name of a "poste FDJ", a "categorie FDJ" and a "personnel" and when I submit the form, it save the id of each name. I know it's possible to save multiple model in one form, I supposed that I can start on this but it doesn't work. Can someone help me? There are my create function controller (that had worked with a "simple" form) and my view : public function actionCreate() { $model = new FeuilleDeJourResponsable(); $meteo_prevision = new MeteoPrevision(); $poste_fdj = new PosteFdj(); $categorie_fdj = new CategorieFdj(); $personnel = new Personnel(); if ($model->load(Yii::$app->request->post()) && $meteo_prevision->load(Yii::$app->request->post()) && $poste_fdj->load(Yii::$app->request->post()) && $categorie_fdj->load(Yii::$app->request->post()) && $personnel->load(Yii::$app->request->post()) && FeuilleDeJourResponsable::validateMultiple([$model, $meteo_prevision, $poste_fdj, $categorie_fdj, $personnel])) { $poste_fdj->save(false); $categorie_fdj->save(false); $personnel->save(false); $model->ID_Poste_FDJ = $poste_fdj->ID_Poste_FDJ; // no need for validation rule on user_id as you set it yourself $model->ID_Categorie = $categorie_fdj->ID_Categorie; // no need for validation rule on user_id as you set it yourself $model->Code_Personnel = $personnel->Code_Personnel; // no need for validation rule on user_id as you set it yourself $model->save(false); // skip validation as model is already validated $meteo_prevision->Date_Calendaire = $model->Date_Calendaire; // no need for validation rule on user_id as you set it yourself $meteo_prevision->save(false); return $this->redirect(['feuille_de_jour_responsable/view', 'Date_Calendaire' => $model->Date_Calendaire]); } else { return $this->render('create', [ 'feuille_de_jour_responsable' => $model, 'meteo_prevision' => $meteo_prevision, 'poste_fdj' => $poste_fdj, 'categorie_fdj' => $categorie_fdj, 'personnel' => $personnel, ]); } } <?php $reqNomPoste = 'SELECT Nom_Poste_FDJ,ID_Poste_FDJ FROM poste_fdj'; $nomPoste = PosteFdj::findBySql($reqNomPoste) ->asArray() ->all(); /*$IDPoste = array(); $i = 0; foreach ($nomPoste["ID_Poste_FDJ"] as $ID) { $i++; $IDPoste = $ID; }*/ //var_dump($nomPoste); $reqNomPersonnel = 'SELECT Nom_Personnel,Code_Personnel FROM personnel'; $nomPersonnel = Personnel::findBySql($reqNomPersonnel) ->asArray() ->all(); //var_dump($nomPersonnel); $reqCategorie = 'SELECT Nom,ID_Categorie FROM categorie_fdj'; $categorie = CategorieFdj::findBySql($reqCategorie) ->asArray() ->all(); //var_dump($nomPersonnel); $form = ActiveForm::begin(); echo FormGrid::widget([ 'model'=>$feuille_de_jour_responsable, 'form'=>$form, 'autoGenerateColumns'=>true, 'rows'=>[ [ 'attributes'=>[ 'ID_Poste_FDJ'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>PosteFdj::find()->select(['Nom_Poste_FDJ', 'ID_Poste_FDJ'])->indexBy('ID_Poste_FDJ')->column(), 'hint'=>'Choisir Poste'], //::findBySql('SELECT Nom_Poste_FDJ,ID_Poste_FDJ FROM poste_fdj'), 'hint'=>'Choisir Poste'] 'Code_Personnel'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>Personnel::find()->select(['Nom_Personnel', 'Code_Personnel'])->indexBy('Code_Personnel')->column(),'hint'=>'Select Personnel'], 'ID_Categorie'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>CategorieFdj::find()->select(['Nom', 'ID_Categorie'])->indexBy('ID_Categorie')->column(), 'hint'=>'Choisir Categorie'], ] ], [ 'attributes'=>[ //'Date_Calendaire'=>['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter username...']], //'Date_Calendaire'=>['type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\DatePicker', 'hint'=>'Enter birthday (mm/dd/yyyy)'], 'Date_Calendaire'=>['type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\DatePicker', 'options' => [ 'pluginOptions' => [ 'todayHighlight' => true, 'format' => 'yyyy-mm-dd', 'multidate' => true, 'multidateSeparator' => ' ; ', ], ], 'hint'=>'Select Date', ], ] ], [ 'attributes'=>[ 'actions'=>[ // embed raw HTML content 'type'=>Form::INPUT_RAW, 'value'=> '<div>' . Html::resetButton('Reset', ['class'=>'btn btn-default']) . ' ' . Html::submitButton('Submit', ['class'=>'btn btn-primary']) . '</div>' ] ], ], ] ]); ?> <?php ActiveForm::end();?> Thank you ! =)
  3. Hi All, This obviously is a trivial question. But I'm spending more time than needed to figure this out.So I seek help here. Whenever I submit a quickform the data is persisted on the fields upon reload. How to make the form non sticky? Cheers, Miraj
  4. I am building a site from the info in this book. And the post I am writing as you read this has a toolbar at the top that allows me to add bold to text, and other cool options. Where could I get a toolbar like this for my website, so I can add it to form fields.? The main thing I am looking for is adding paragraphs when people type 2 carriage returns on their keyboard. So that the text area form field behaves like as if you are typing in a word processing document. Adding bold to text, italics, and underline would be great too, but as a beginner I can accept if the paragraphs is all I can handle code-wise. I do know some javascript, so if coding it involves that I might be able to. Any ideas on how to go about this would be wonderful!
  5. We have been using the following script (based on the book script) to deliver a booking form very successfully for some time. However, just recently occasionally a customer submits a form that is not delivered, despite them coming to the "thank you" confirmation. We do not receive the form, does not go to spam, etc. Despite repeated attempts, these customers cannot send the form successfully, while we receive many other forms without problems. Is there anything in the code that would allow the customer to get through to the "confirmation" part while the "send" is not executed successfully? Or could the only explanation be a problem in the delivery chain rather than our implementation of the form? Any advice would be appreciated, thank you. Our script is: <?php # Script 12.1 - email.php #2 // Check for form submission: if (isset($_POST['submitted'])) { /* The function takes one argument: a string. * The function returns a clean version of the string. * The clean version may be either an empty string or * just the removal of all newline characters. */ function spam_scrubber($value) { // List of very bad values: $very_bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:', '#'); // If any of the very bad strings are in // the submitted value, return an empty string: foreach ($very_bad as $v) { if (stripos($value, $v) !== false) return ''; } // Replace any newline characters or link code characters with spaces: $value = str_replace(array( "\r", "\n", "%0a", "%0d", "http://", "www.", "<a", "</a>"), ' ', $value); // Return the value: return trim($value); } // End of spam_scrubber() function. // Clean the form data: $scrubbed = array_map('spam_scrubber', $_POST); // Minimal form validation: if (!empty($scrubbed['accept_conditions'])) { // Create the body: $body = 'Sent At ' . date("H:i:s") . ' on ' . date("d/m/Y") . "\n\nSent By {$scrubbed['contact_name']} {$scrubbed['email']}\n\n-----------------\n\nEXPERIENCE 1\n\nExperience Name: {$scrubbed['experience_name']}\n\nStart Date: {$scrubbed['experience_start']}\n\nEnd Date: {$scrubbed['experience_end']}\n\n\n\nEXPERIENCE 2\n\nExperience Name 2: {$scrubbed['experience_name_2']}\n\nStart Date 2: {$scrubbed['experience_start_2']}\n\nEnd Date 2: {$scrubbed['experience_end_2']}\n\n\n\nPERSONAL DETAILS\n\nPERSON ONE\n\nName: {$scrubbed['one_first_name']} {$scrubbed['one_surname']}\n\nNationality: {$scrubbed['one_nationality']}\n\nDOB: {$scrubbed['one_dob']}\n\nGender: {$scrubbed['one_gender']}\n\nHealth-Diet: {$scrubbed['one_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['one_ins_co']}, {$scrubbed['one_pol_no']}, {$scrubbed['one_exp_date']}\n\n\nPERSON TWO\n\nName: {$scrubbed['two_first_name']} {$scrubbed['two_surname']}\n\nNationality: {$scrubbed['two_nationality']}\n\nDOB: {$scrubbed['two_dob']}\n\nGender: {$scrubbed['two_gender']}\n\nHealth-Diet: {$scrubbed['two_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['two_ins_co']}, {$scrubbed['two_pol_no']}, {$scrubbed['two_exp_date']}\n\n\nPERSON THREE\n\nName: {$scrubbed['three_first_name']} {$scrubbed['three_surname']}\n\nNationality: {$scrubbed['three_nationality']}\n\nDOB: {$scrubbed['three_dob']}\n\nGender: {$scrubbed['three_gender']}\n\nHealth-Diet: {$scrubbed['three_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['three_ins_co']}, {$scrubbed['three_pol_no']}, {$scrubbed['three_exp_date']}\n\n\nPERSON FOUR\n\nName: {$scrubbed['four_first_name']} {$scrubbed['four_surname']}\n\nNationality: {$scrubbed['four_nationality']}\n\nDOB: {$scrubbed['four_dob']}\n\nGender: {$scrubbed['four_gender']}\n\nHealth-Diet: {$scrubbed['four_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['four_ins_co']}, {$scrubbed['four_pol_no']}, {$scrubbed['four_exp_date']}\n\n\nPERSON FIVE\n\nName: {$scrubbed['five_first_name']} {$scrubbed['five_surname']}\n\nNationality: {$scrubbed['five_nationality']}\n\nDOB: {$scrubbed['five_dob']}\n\nGender: {$scrubbed['five_gender']}\n\nHealth-Diet: {$scrubbed['five_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['five_ins_co']}, {$scrubbed['five_pol_no']}, {$scrubbed['five_exp_date']}\n\n\nPERSON SIX\n\nName: {$scrubbed['six_first_name']} {$scrubbed['six_surname']}\n\nNationality: {$scrubbed['six_nationality']}\n\nDOB: {$scrubbed['six_dob']}\n\nGender: {$scrubbed['six_gender']}\n\nHealth-Diet: {$scrubbed['six_extras']}\n\nInsurer, Policy Number, Expiry date): {$scrubbed['six_ins_co']}, {$scrubbed['six_pol_no']}, {$scrubbed['six_exp_date']}\n\n\n\nOPTIONAL EXTRAS\n\n{$scrubbed['optional_extras']}\n\n\n\nCLIMATE CARE OR CHARITY DONATION\n\nPerson 1: {$scrubbed['one_charity']}\n\nPerson 2: {$scrubbed['two_charity']}\n\nPerson 3: {$scrubbed['three_charity']}\n\nPerson 4: {$scrubbed['four_charity']}\n\nPerson 5: {$scrubbed['five_charity']}\n\nPerson 6: {$scrubbed['six_charity']}\n\n\n\nCONTACT DETAILS\n\nContact Name: {$scrubbed['contact_name']}\n\nContact Address: {$scrubbed['contact_address']}\n\nContact Town: {$scrubbed['contact_town']}\n\nContact Postcode: {$scrubbed['contact_postcode']}\n\nContact Telephone: {$scrubbed['contact_tel']}\n\nContact Mobile: {$scrubbed['contact_mobile']}\n\nContact Email: {$scrubbed['email']}\n\nNewsletter: {$scrubbed['newsletter']}\n\n\n\nEMERGENCY CONTACT\n\nEmergency Name: {$scrubbed['emergency_name']}\n\nEmergency Telephone: {$scrubbed['emergency_tel']}\n\nEmergency Mobile: {$scrubbed['emergency_mobile']}\n\nPAYMENT INFORMATION\n\nDeposit Total: {$scrubbed['deposit_total']}\n\nDonation Total: {$scrubbed['climate_care_total']}\n\nTotal Amount: {$scrubbed['total_amount']}\n\nPaying By: {$scrubbed['payment_option']}\n\n\n\nOTHER INFORMATION\n\nNotes: {$scrubbed['notes']}\n\nAccept Conditions: {$scrubbed['accept_conditions']}\n\n"; $body = wordwrap($body, 90); // Send the email: mail('OUR EMAIL ADDRESS REMOVED HERE', 'Online Booking Form', $body, "From: {$scrubbed['email']}"); // Print a message: echo 'OUR THANK YOU MESSAGE REMOVED HERE'; // Clear $_POST (so that the form's not sticky): $_POST = array(); } } // End of main isset() IF. ?> <?php if (isset($_POST['submitted'])) { if (empty($scrubbed['accept_conditions'])) { echo '<p class="make_red"><span class="highlighted_text">Please tick the "I accept" box at the bottom of the form to agree to booking conditions</span></p>'; } } ?>
  6. I want to create a contact form that has an email field where the user can't enter any white space in the field, for example: test@ex ample.com I am using a spam scrubbing function taught to us in the book to clean user inputs. I am using my variable like so. $email = strip_tags($scrubbed['email']); how can I add something like this $email = preg_replace('/\s+/', '', $email); to the existing $email = strip_tags($scrubbed['email']); I tried $email = (preg_replace('/\s+/', '', $email)(strip_tags($scrubbed['email']))); and all sorts of variations to that. it doesn't work.
  7. Hey, I am currently reading the book, and have made my own register form and php script. There is no problems with the database connection, but it just will not insert information into the database. The MySQL database is named 'test' and the table 'users'. The table has user_id, first_name, last_name, email, pass and registration_date columns. here is the registration form: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body><link rel="stylesheet" type="text/css" href="style.css"> <form action="script4.php" method="post"> <p>First Name:<input type="text" name="first_name" /></p> <p>Last Name:<input type="text" name="last_name" /></p> <p>Email: <input type="text" name="email" /></p> <p>Password: <input type="password" name="pass1" /></p> <p>Confirm Password: <input type="password" name="pass2" /></p> <input type="submit" name="submit" value="Submit!" /> </form> </body> </html> and here is script4.php : <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php $first_name = $_REQUEST['first_name']; $last_name = $_REQUEST['last_name']; $email = $_REQUEST['email']; $pass1 = $_REQUEST['pass1']; $pass2 = $_REQUEST['pass2']; require ('mysql_connect.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array();} if (!empty($_POST['first_name'])) { $errors[] = "You forgot to enter your first name!"; } else { $fn = trim($_POST['first_name']); } if (!empty($_POST['last_name'])) { $errors[] = "You forgot to enter your first name!"; } else { $ln = trim($_POST['last_name']); } if (!empty($_POST['email'])) { $errors[] = "You forgot to enter your first name!"; } else { $e = trim($_POST['email']); } if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = "Your passwords do not match."; } else { $p = trim($_POST['pass1']);} }else { $errors[] = "You forgot to enter your password."; } if (empty($errors)) { require ('mysql_connect.php'); @mysqli_query("INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES($first_name, $last_name,$email, SHA1($pass), NOW() )");} ?> </body> </html> Please can someone help me. I am using WAMP server by the way.
  8. I am working with the "secure" version of contact form script 12.1 described in "Chapter 12 - Security Methods" (pg. 365) but would like to modify this so that rather than simply printing a thank you message, the user is redirected to a thank you page. I have tried replacing the given script: // Minimal form validation: if (!empty($scrubbed['email'])) { // Create the body: $body = "Name: {$scrubbed['name']}\n\nComments: {$scrubbed['comments']}"; $body = wordwrap($body, 70); // Send the email: mail('XXX@XXX', 'Contact Form Submission', $body, "From: {$scrubbed['email']}"); // Print a message: echo '<p><em>Thank you for contacting me. I will reply some day.</em></p>'; // Clear $_POST (so that the form's not sticky): $_POST = array(); } else { echo '<p style="font-weight: bold; color: #C00">Please enter a valid email address.</p>'; } with modified: // Minimal form validation: if (!empty($scrubbed['email'])) { // Create the body: $body = "Name: {$scrubbed['name']}\n\nComments: {$scrubbed['comments']}"; $body = wordwrap($body, 70); // Send the email: mail('XXX@XXX', 'Contact Form Submission', $body, "From: {$scrubbed['email']}"); // Redirect to thank you page: header("Location: thankyou.htm"); exit(); // Clear $_POST (so that the form's not sticky): $_POST = array(); } else { echo '<p style="font-weight: bold; color: #C00">Please enter a valid email address.</p>'; } ..but get the error: Warning: Cannot modify header information - headers already sent by (output started at /websites..... Reading about this, it seems nothing can be sent to the browser before header is used. But however I try to move things around, I cannot get this to work. Could you advise how/where this redirect should be used within this script? Thank you.
  9. Hi. First off, this is in regards to exercise dealing with using a foreach loop instead of implode(). I was having trouble with it, and of course looked up what was posted here already, but I want to do more. By the I mean I wanted to validate that the form data was not empty, had no numbers, and had a minimum of five words that will of course be alphabetized(though I'd rather being doing some analysis with it for simple patterns like the avg number of characters by word, number of vowels, number of constants, but let me just be simple about it for now). Here's the code(just a note, to give credit where it's due this is code I've altered that was posted here originally): $flag = true; $words_Array = $_POST['words']; $count1 = count($words_Array); // turn the incoming string, $_POST['words'], into an array and validate: if (empty($words_Array) || (is_numeric($words_Array) ) || ($count1 < 5) ) { print "<p>Please enter at least five words and no numbers.</p>"; $flag= false; } else { $words_Array = explode (' ', $_POST['words']); } //sort the words alphabetically if ($flag) { sort($words_Array); } if ($flag) { print "<p>An alphabetized version of your list is: "; foreach ($words_Array as $key => $value) { print "<br />\n $value "; } } print "</p>"; ?> Now, I've run this code and whether I enter five words or four words and a number, it still runs the print statement inside the first if statement "Please enter at least five words and no numbers." So what I'm I missing here logic wise? Also I'm thinking this code could much cleaner without having to be redundant by using three separate if statements, would an if-elseif-else be a good choice/best practice ? Lastly, can validation be done without using a boolean "flag" variable ? Assistance is greatly appreciated.
  10. I'm trying to build an online tool checkout application, so I'm working with script 10.5 to pull (tool names) from a database to populate a table. I need to be able to select multiple tools (using checkboxes), and then submit that form to a shopping cart. I've been able to add a checkbox to each result, but is this the correct way to give each checkbox the name associated with it? // Fetch and print all the records.... $bg = '#eeeeee'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['category'] . '</td> <td align="left">' . $row['name'] . '</td> <td align="left"> <form action="view_cart.php" method="post"> <input type="checkbox" name="checked" value="$row['name']" /> </td> '; } // End of WHILE loop. And then to display the results? if ($_SERVER['REQUEST_METHOD'] == 'POST') { while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) { echo "\t<tr> <td align=\"left\">{$row['name']}</td> </tr>\n"; } // End of the WHILE loop. It just feels like a shot in the dark, and so I wanted to ask.
  11. On my registration page, I would like to allow my clients to select from two different options as roles they can have when they register for the website. The first role is "member", the second is "manager". I can't find any resources on how the syntax should work with the create_form_input tag to allow the user to select one of those two options and store it in the database under the "type" field. Please help! Jim
  12. Hi all, I've created a search page on my website with pagination from the book. If a search is entered with an apostrophe, the first time the search page (and sticky form value) is loaded, it looks fine, but as you click on each of the page links, the apostrophe is escaped again, adding slashes into the form value and the url: Initial search of Mother's Day: http://aqualee.com/n...=Mother%27s+Day After clicking back & forth on the previous/next page links a couple times: http://aqualee.com/new/search.php?keyword=Mother\\\\\\\'s%20Day&s=6&p=2 My best guess is that it's applying htmlspecialchars (for the page title & form value) and/or mysqli_real_escape_string (for the keyword in the url) with each page load, but I can't figure out the logic in how to avoid that while keeping the data safe. This update to my site is my first foray into PHP or SQL, and I have as much experience in programming as a semester in C++ can give you. Here's the relevant code (I think!)... $show_keyword is set and used in the title and form value here // set page title if (isset($_GET['keyword'])) { $show_keyword = htmlspecialchars($_GET['keyword']); } $page_title = 'Search results for '.$show_keyword.' greeting cards by Aqua Lee'; include ('header.html'); // create text form to search with sticky value echo '<form action="search.php" method="GET"> <label>Search: <input type="text" name="keyword" size="20" maxlength="50" value="'.$show_keyword.'" /></label> <input type="submit" value="Search" /></form>'; $search_term is set & escaped here // validate and secure user entry if (!empty($_GET['keyword']) ) { $search_term = mysqli_real_escape_string($dbcon, trim($_GET['keyword']) ); } $search_term is used in the urls where extra slashes show # create pagination links // Make the links to other pages, if necessary. if ($pages > 1) { echo '<br /><p>'; $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button: if ($current_page != 1) { echo '<a href="search.php?keyword='.$search_term.'&s=' . ($start - $display) . '&p=' . $pages. /*. '&sort=' . $sort . */'">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="search.php?keyword='.$search_term.'&s=' . (($display * ($i - 1))) . '&p=' . $pages./* . '&sort=' . $sort . */'">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next button: if ($current_page != $pages) { echo '<a href="search.php?keyword='.$search_term.'&s=' . ($start + $display) . '&p=' . $pages./* . '&sort=' . $sort . */'">Next</a>'; } echo '</p>'; } Can you tell me where the redundancy is, if that's the problem? Do I even need to escape the form input if I'm just displaying it in the title or in the form? I read about some similar problems with apostrophe, and magic quotes were suggested to be the culprit...they are turned off in my php.ini file. Thanks for taking a look!! -Marilee
  13. First off, what a well written technical book! Thanks Larry. I'm working on a project that currently uses JavaScript validation. The page will have PHP functionality later, but after reading chapter 6's validation examples, I got to thinking . . . Can I have slicker AJAX style same page validation using PHP? This would put the error messages in the same page after form field completion but before submission. I saw an example elsewhere that essentially points the action to the same page, but it used a lot of "include" scripting. The validation scripting in the book is so simple, yet the JavaScript currently being used in my project seems so unnecessarily clunky. So, in short, what is the easiest way to augment the validation example in the book for same page validation? Would it be more efficient than AJAX validation?
×
×
  • Create New...