Jump to content

Search the Community

Showing results for tags 'form'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. As the title states, I am trying to process a form and save the form's data as a new page. I have looked at Soma's post, but it seems (as least to me), that it tackles submission forms etc. I know what I am trying to do is very very similar. The Form: <form role="form" method="post" action="./" > <div class="form-group"> <label for="code">Enter 4-Digit Code:</label> <input type="code" class="form-control" id="code"> </div> <button type="submit" name="submit" class="btn btn-default">Submit</button> </form> And the processing: if($input->post->submit) { $code = Trim(stripslashes($_POST['code'])); $p = new Page(); $p->setOutputFormatting(false); $p->template = 'singular'; // example template $p->parent = wire('pages')->get('/'); // example parent $p->name = $code; // example name $p->title = "Test Title"; $p->save(); echo "page ID {$p->id} created!<br>"; } else { // output contact form echo "Negative Ghost Rider"; } ?> I have been scratching my head as to why this doesn't seem to work for about an hour. I am sure I must be missing something, or trying to go about this the wrong way. The form seems like it submits, but there is no page added to the backend.
  2. I am trying to apply onkeyup or jquery keyup to a PW form - to autogenerate a username from a real name. This javascript/jquery works fine on test html input fields: But I can't get it to work on the fields generated by the PW forms API, even though the input id names are exactly the same. What am I missing?
  3. Hello, I am using the form API for forms, and I have some defaults that are saved via a cookie. So if someone has visited the site previously, if they return to complete a query form etc, the idea is that these are prepopulated in the form. I am using InputFields and using $fieldname->render() to create the form fields. Can I just set the value of an Input field (after first checking we are not in the middle of a POST)? What I don't get is when Inputfield get populated from POST - it seems to be populated as soon as it gets instanced, because if the form is completed, but has errors, the form field contents get remembered from the POST, even through I haven't done a processInput yet. I am guessing I can't just say $nameformfield->value ? $formfield->value : $_COOKIE['name'];
  4. Hello everyone, I need to rewrite entire application and I want to choose PW for speed reason and logic. I love the roles/permissions system and relationships in db, but now the question.. My app is based on users roles, foreach user role I need to write a big form (around 30fields)->store in database->edit and show the form. Simple crud system in frontend. I can not find a guide to do this, I would use as much as possible the PW's API can you give me some advice? edit: this module works fine! http://modules.processwire.com/modules/form-template-processor/ @ryan with the upload fields the page say "The page must be saved" my code in my template is: $form = $modules->get('FormTemplateProcessor'); $form->template = $templates->get('my_template'); $form->requiredFields = array('field1', 'field2', 'field3'); $form->parent = $page; echo $form->render(); Thank you all guys!
  5. I need to create an electronic gateway that will hide a particular file until a user first enters and confirms their country of residence, and I'm not sure where to start. The basic process is – a form is displayed asking for country of residence, a checkbox for terms and conditions, and a submit button. After passing this there is a second screen which reiterates the conditions, possibly with extra information, and a second checkbox/submit button. Passing that will display the file. They's also like to obfuscate the URL or similar, so the screens above can't be bypassed and the file accessed directly. I've been looking through the creating forms with the api thread but it's a very long topic and Ive not been able to get very far with it. I implemented Soma's first bit of code from that thread but it doesn't seem to process the form/pick up any errors, etc. Is this the best route to stick with, or would FormBuilder be a good alternative?
  6. Hello, I am building one form to send email with WireMailSmtp every thing is working fine, only thing attachments are sending with email without any extension. what i want to do is 1. first check the attached file and only allow image/ pdf and word file to be attached 2. send email with attachment. here is my code if (isset($input->post->submit)) { $form = array( 'name' => $input->post->name, 'email' => $input->post->email, 'message' => $input->post->message, 'email2' => $input->post->email2 ); $photo=$filetemp = $_FILES["photo"]; /// how to check that file is only image $resume=$filetemp = $_FILES["resume"]; /// how to check the file is only PDF or word file /// email12 is for spam boot if($form[email2] =="") { $toName='my website'; $toEmail=$page->email; $subject="CV EMail"; $textBody= "Full name: $form[name]\n" . "Email: $form[email]\n" . "Message: $form[message]"; $mail = wireMail(); $mail->to($toEmail, $toName); $mail->from = $toEmail; $mail->subject($subject); $mail->attachment($photo); $mail->attachment($resume); $mail->body($textBody); $numSent = $mail->send(); if($numSent) { $output="Message Send"; }else{ $output="Message Not Send"; } } }
  7. i have problem with send muliple files, for one file it works, for multiple not, what should I do with this code ? <?php if($_POST){ unset($_POST["send"]); //print_r($_POST); unset($_POST["pliki"]); $p = new Page(); $p->template = 'page'; $p->parent = '1043'; $p->user_id = $user['id']; foreach($_POST as $v=>$pr){ if($pr!=''){ $p->{$v} = $pr; } } $p->save(); $pp = $pages->get($p->id); $pp->setOutputFormatting(false); if(isset($_FILES['pliki'])){ $errors= array(); $file_name = $_FILES['pliki']['name']; $file_size =$_FILES['pliki']['size']; $file_tmp =$_FILES['pliki']['tmp_name']; $file_type=$_FILES['pliki']['type']; $file_ext=strtolower(end(explode('.',$_FILES['pliki']['name']))); //$name = strtolower($sanitizer->name($file_name)); //'../../site/assets/files/'.$p->id.'/'.$name) $expensions= array("jpeg","jpg","png","docx","doc","pdf"); if(in_array($file_ext,$expensions)=== true){ move_uploaded_file($file_tmp,"../../site/assets/files/".$pp->id."/".strtolower($sanitizer->name($file_name))); $pp->pliki->add($file_name); } } $pp->save(); } ?> My input looks like this: <input type="file" id="pliki" name="pliki[]" multiple>
  8. Hi all, I need a page for users to post questions to moderators. I'm reusing the Discussions module and the Comment module for the replies (I didn't like the idea of having hundred of pages for replies so I modified it). To handle the form, the Discussions module to autoload in every pages and I think it could pose performance issue. So my question is: Is there anyway for a module to handle a submitted form without setting autoload = true? i.e. processwire loads the module on-demand.
  9. Hi everyone, I'm having a problem with a form I'm creating using the api. The form consist on multiple text fields, one file, and an Options field, everything works fine, except for the options field. The form creates fine, the main problem is on submit. I'm getting this error: Warning: Invalid argument supplied for foreach() in C:\Local\htdocs\wire\modules\Fieldtype\FieldtypeOptions\FieldtypeOptions.module on line 277 I already tried to check the type and use $post_value->id but it's not working. My code: if($input->post->submit_save) { // user submitted the form, process it and check for errors $form->processInput($input->post); $errors = array(); $required_fields = array(); $fields = array(); $post_value = $input->post->{$f->name}; switch ( $f->type ) { case 'text': $the_value = $sanitizer->text( $post_value ); break; case 'textarea': $the_value = $sanitizer->textarea( $post_value ); break; case 'checkbox': $the_value = isset( $post_value ) ? 1 : 0; break; default: $the_value = $post_value; break; } $fields[$f->name] = $the_value; foreach ( $fields as $key => $value ) { $page->$key = $value; } $page->of(false); $page->save(); } Any Ideas? Thanks
  10. Hello, I am building a frontend form following Soma's great example on a PW 2.7.2 stable install. The pages that I edit with the form already exist. My form includes a single image field, CKEditor fields and some normal text fields. The form renders fine, all CSS and JS is in place. I can even use the pwImage plugin on the CKEditor field and it loads the image from that page. When there already is an image present in the image field and I submit the form, I get this error: Fatal error: Exception: Method Pageimage::path does not exist or is not callable in this context (in /var/www/utgpwnew/wire/core/Wire.php line 358) #0 [internal function]: Wire->___callUnknown('path', Array) #1 /var/www/utgpwnew/wire/core/Wire.php(398): call_user_func_array(Array, Array) #2 /var/www/utgpwnew/wire/core/Wire.php(333): Wire->runHooks('callUnknown', Array) #3 /var/www/utgpwnew/wire/core/Wire.php(337): Wire->__call('callUnknown', Array) #4 /var/www/utgpwnew/wire/core/Wire.php(337): Pageimage->callUnknown('path', Array) #5 /var/www/utgpwnew/wire/modules/Fieldtype/FieldtypeFile.module(119): Wire->__call('path', Array) #6 /var/www/utgpwnew/wire/modules/Fieldtype/FieldtypeFile.module(119): Pageimage->path() #7 /var/www/utgpwnew/wire/core/Wire.php(459): FieldtypeFile->hookProcessInput(Object(HookEvent)) #8 /var/www/utgpwnew/wire/core/Wire.php(333): Wire->runHooks('processInput', Array) #9 /var/www/utgpwnew/wire/core/InputfieldWrapper.php(636): Wire->__call('processInput', Array) #10 /var/www/utgpwnew/wire/core/Inp in /var/www/utgpwnew/index.php on line 248 If the image field is empty, I get this error on submit Fatal error: Call to a member function path() on a non-object in /var/www/utgpwnew/wire/modules/Fieldtype/FieldtypeFile.module on line 119 If I change the image field to hold more than one image, I don't get the error and the form submits fine with and without one or more images in the field From debugging I see that the error is triggered from $form->processInput($this->input->post); So the code does not work on single image fields. Is there a way to fix this? Any help would be much appreciated.
  11. How can I achieve something like this where I can add more Conditions or delete them: Inside this Form where I create Segments for a Mailchimp Account Form processing looks like this: if($this->input->post->createSegment) { $form->segmentnameParam->required = 1; $form->fieldParam->required = 1; $form->operatorParam->required = 1; $form->searchParam->required = 1; $form->match->required = 1; $form->processInput($this->input->post); if(!$form->getErrors()) { $segment_name = $this->sanitizer->text($form->get("segmentnameParam")->value); $field_name = $form->get("fieldParam")->value; $operator = $form->get("operatorParam")->value; $search_value = $this->sanitizer->text($form->get("searchParam")->value); $match = $this->sanitizer->text($form->get("match")->value); $res = $this->mailchimp->call("/lists/segment-add", array( "id" => $list_id, "opts" => array( "type" => "saved", "name" => $segment_name, "segment_opts" => array( "match" => $match, "conditions" => array( array( "field" => $field_name, "op" => "eq", "value" => $search_value, ) ) ) ) )); if($res){ $this->message(sprintf($this->_("Created new Segment called: '%s'"), $segmentnameParam)); } $this->session->redirect("../edit/?id=$list_id"); } }
  12. Hello, I try to realize some booking form via jQuery.post method. It works to send the data to the book.php file. Whats next ? How to handle the data right. this is the JS code jQuery.post("./book.php",{ xx_name: name, xx_email: email, xx_date: date, xx_time: time, xx_message:message, xx_contact: contact}, function(data) { jQuery(".book_online_form .returnmessage").append(data);//Append returned message to message paragraph if(jQuery(".book_online_form .returnmessage span.book_error").length){ jQuery(".book_online_form .returnmessage").slideDown(500).delay(2000).slideUp(500); }else{ jQuery(".book_online_form .returnmessage").append("<span class='book_success'>"+ success +"</span>") jQuery(".book_online_form .returnmessage").slideDown(500).delay(4000).slideUp(500); setTimeout(function(){ $.magnificPopup.close() }, 5500); } if(data==""){ jQuery(".book_online_form")[0].reset();//To reset form fields on success } }); It works for me i get the data but what now ? how to handlte this right ? this is the post.php <?php include("./index.php"); // include header markup $sent = false; $error = ''; $emailTo = 'my@email.here'; // or pull from PW page field // sanitize form values or create empty $form = array( 'fullname' => $sanitizer->text($input->post->name), 'email' => $sanitizer->email($input->post->email), 'comments' => $sanitizer->textarea($input->post->message), ); print "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "<BR />"; $data = file_get_contents('php://input'); // Dont really know what happens but it works print "DATA: <pre>"; var_dump($data); var_dump($_POST); var_dump($form); print "</pre>"; if($input->post->submit) { $name = $_REQUEST['xx_name']; echo "Welcome 1". $name; // DONT WORK }else{ echo "Something is wrong on the submit "; } if( $_REQUEST["xx_name"] ) { $name = $_REQUEST['xx_name']; echo "Welcome 2". $name; // WORK } I have attached the output. how to act with the pw $input->post->submit and the form array for example ??
  13. Hey guys, I'm really really desperate for help at this stage, for my own sanity mostly. I've been trying to set up a form that requires several fields one of which is a file upload, the user can upload max 10 files with extension jpg/png/jpeg and these are sent to the admin email as attachments. Currently this i am using the InputfieldFile module, I have moved it over to /site/modules because hooking the return html wasn't enough for my needs. So basically I have this. $images = $modules->get("InputfieldFileCustom"); $images->attr('label', "Upload your images"); $images->required = 0; $images->maxFiles = 10; $images->attr('id+images','image'); $images->attr('placeholder','no file selected'); $images->attr('extensions','jpg'); $form->append($images); I expected output that would allow me to upload and delete files. Except right now my biggest issue is the fact that the remove button isn't being displayed because the ___renderItem method isn't being run and I have no idea how to make this work. I'm going to have to do a lot of fun stuff with the markup for the majority of the render methods but I can't do anything until I get the remove button to display. I also made a inputfieldfilecustom.js which is imported on the page. I've renamed all instances of InputFieldFile to InputFIeldFileCustom (in both js and module) Begging for help around now. it would be incredibly appreciated if someone can give me any direction.
  14. Is there a free way for me to add a contact form in my PW site? As far as I know I should buy the form builder module for that?
  15. This has probably been asked a million times, but I can't seem to find an answer. I have always just used a php script to process the emails and was excited that I could pass in an email address from a page to the script using $page. However, this does throw a 403. I was told that I shouldnt be doing it this way, but I was wondering how do you all go about handling emails? I was going to use the same page template, but I need the option of changing out the to email address dynamically.
  16. I have a contact form that feeds to a engine.php. However when I go to fill it out, I get a 403 error )permission denied. I am using mamp, so maybe it is an issue with this. However, I was wondering if anyone else had run into this problem before. I have the url to the .php file using " <?php echo $config->urls->templates?>form/
  17. Hi, I'm about to start developing a website in Processwire but did a bit of research and could'nt find any way to create a form with confirmation message loaded by AJAX when a form is submitted + validated. Is that possible? I think of something similar to Contact Form 7 for WP (when the visitor submits the form it should get validated and if every field validates and email gets sent the visitor gets a message like "Thank you for your message!" without page reload). Is that possible to do this in Processwire or anything thats on the Feature list? From what i can understand theres three modules (Form builder, Form Template Processor and Mailer and Simple Contact Form) that can create forms and also a API-function to call and create the form manually. Is there any of the above which supports ajax submit with "Thank you"-message on the same page without reloading the page on submit? Seems pretty basic, but maybe i've missed something. Thank you!
  18. I have the following sidebar.inc included on my Shop page which is the main index of items: <?php foreach($input->get as $key => $val) { echo htmlentities("$key = $val") . "<br>"; } $selector = ''; $summary = array( "categories" => "", "agegroups" => "", "keywords" => "", ); if($input->get->categories) {} $sidebar = "<form id='search_form' method='get' action='{$config->urls->root}shop/'><div class='row'>"; $taxonomies = $pages->find("template=product_taxonomies"); foreach($taxonomies as $t) { $items = $t->children; $sidebar .= "<div class='small-6 large-12 columns'><h3>{$t->title}</h3>"; foreach($items as $i) { $sidebar .= "<input id='$i->name' name='$t->name' value='$i->name' type='checkbox'><label for='$i->name'>$i->title</label><br>"; } $sidebar .= "</div>"; } $sidebar .= "<input id='search_keyword' name='keyword' type='text'/>"; $sidebar .= "<div class='large-12 columns'><input type='submit' id='search_submit' name='submit' value='Search'></div></div></form>"; Checking more than one input of the same name only produces the last value of those. Can anyone advise me on how to make these multi-select filters return multiple values?
  19. Hello, from the day i am using PW every day i am loving it more and more, its really great. i am trying to create a page for website where people can apply for job and send CV as attachment too. i was searching forums from last few days and create one page with combinations of many posts in form, my code is bellow. <style> #email2 { display:none; } #message-error { color:#F00;} #message-success { color:#09F;} </style> <?php // check if the form was submitted $spam_check=trim($input->post->email2); if($input->post->submit && $spam_check == '') { $sent = false; $error = ""; $emailTo = $page->email; // sanitize form values or create empty $form = array( 'fullname' => $sanitizer->text($input->post->fullname), 'job_title' => $sanitizer->text($input->post->job_title), 'job_id' => $sanitizer->text($input->post->job_id), 'contact' => $sanitizer->text($input->post->contact), 'email' => $sanitizer->email($input->post->email), 'comments' => $sanitizer->textarea($input->post->comments), ); $msg = "Full Name: $form[fullname]\n" . "Contact number: $form[contact]\n" . "Job Title: $form[job_title]\n" . "Job Id: $form[job_id]\n" . "Email: $form[email]\n" . "Comments: $form[comments]"; // attachment if(isset($_POST['submit']) && !empty($_FILES['file']['size'])) { $filename = $_FILES["file"]["name"]; $filetype = $_FILES["file"]["type"]; $filesize = $_FILES["file"]["size"]; $filetemp = $_FILES["file"]["tmp_name"]; if($filesize < 10) throw new Exception("File too small"); if($filesize > 1000000) throw new Exception("File too big"); $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if(!in_array($ext, array('doc', 'pdf', 'docx'))) throw new Exception("Invalid file type"); $destination = $config->paths->cache . $user->name . '.' . $ext; if(!move_uploaded_file($filetemp, $destination)) throw new Exception("Unable to move uploaded file"); $fp = fopen($destination, "rb"); $file = fread($fp, $filesize); $file = chunk_split(base64_encode($file)); unlink($destination); } // This two steps to help avoid spam $headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n"; $headers .= "X-Mailer: PHP v".phpversion()."\r\n"; // With message $headers .= "Content-Type: text/html; charset=utf-8\r\n"; $headers .= "Content-Transfer-Encoding: 8bit\r\n"; $headers .= "".$message."\n"; $headers .= "--".$num."\n"; // Attachment headers $headers .= "Content-Type:".$filetype." "; $headers .= "name=\"".$filename."\"r\n"; $headers .= "Content-Transfer-Encoding: base64\r\n"; $headers .= "Content-Disposition: attachment; "; $headers .= "filename=\"".$filename."\"\r\n\n"; $headers .= "".$file."\r\n"; $headers .= "--".$num."--"; if(mail($emailTo, "Job Application", $msg, "From: $form[email]",$headers)) { // populate body with success message, or pull it from another PW field $messageok = "<div id='message-success'><p>Thanks, your message has been sent.<b>We will Contact you back</p> </div>"; $sent = true; }else{ $error= "<div id='message-error'><p>Error! Mail Not Sent.</p></div>"; $sent = false; } } include("./head.inc"); ?> here is my form code Please enter your contact details below.<br /><br /> <?php if(strlen($error)>1) { echo $error; } // to get JOB title and id $job=$pages->get($input->urlSegment1); if(!$sent) { ?> <form action="./" method="post" class="contact-form" id="contactform"> <input id="job_title" name="job_title" type="hidden" value="<?php echo $job->title;?>" /> <input id="job_id" name="job_id" type="hidden" value="<?php echo $job->job_id;?>" /> <input Placeholder="Please Enter Your Name" name="fullname" id="fullname" value="<?php echo $form[fullname];?>" /> <input type="text" Placeholder="Please Enter Your Contact Number" name="contact" id="contact" value="<?php echo $form[contact];?>" /> <input type="text" name="email" id="email" Placeholder="Please Enter Your Email" /> <input type="file" name="file" id="file" value="Uplode Cv" /> <textarea id="comments" name="comments" cols="60" rows="3" Placeholder="Please Enter Your Message"><?php echo $form[comments];?> <input type="text" name="email2" id="email2"> <input name="submit" id="submit" type="submit" value="Send" /> </form> <?php }else{ echo $messageok; } include("./foot.inc"); ?> form is displaying properly but emails are not going and i am getting error "Error! Mail Not Sent." what i want to do is send email with attachment and then delete uploaded file from server and of course secure. really appreciate your update. Thanks
  20. Hello, i am trying to built one job search form but its not working, bellow is my code <form method="get" action="<?=$config->urls->root;?>search/"> <input type="text" placeholder="Keyword Search" name="keyword" id="keyword"> <select name="job_sector" id="job_sector"> <option>All Sectors</option> <option>Human Resources</option> <option>Consulting</option> </select> <select name="job_level" id="job_level"> <option>All Jobs Level</option> <option>Executive</option> <option>Manager</option> </select> <select name="job_location" id="job_location" > <option>All Locations </option> <option>city1</option> <option>city2</option> </select> <input type="submit" class="btn btn-primary btn-medium" value="Search Jobs" > </form> <?php $search_cat=""; // find any matching keyword if($input->get->job_keyword) { $search_cat="job_keyword~=".$input->get->job_keyword; } if($input->get->job_sector) { $search_cat=$search_cat.",job_sector=".$input->get->job_sector; } if($input->get->job_level) { $search_cat=$search_cat.",job_level=".$input->get->job_level; } if($input->get->job_location) { $search_cat=$search_cat.",job_location=".$input->get->job_location; } $jobs=$pages->find("template=job,$search_cat"); foreach($jobs as $job) { ?> but this code is not working. i want to find all pages with template job and any field select on form. Thanks
  21. Hi there, I’ve built a form containing a list of products and their price. Some of these products got no exact price, mean it is individual. Ive read the API from InputSelect.module, but I don’t really understand how to add attributes to my options from the selectbox. I am adding products like this: $field->addOption($prod->product_title); Now I want to add also an attribute „disabled“ if there is no value for price. Like: if(!$prod->product_price) { // Code needed } Can somebody help me to solve this? Greetings from Nuremberg.
  22. Hi! Just started to dig into PW and since I have a small project starting I wonder that how does PW support dynamic forms out-of-the-box? Or perhaps through some module(s)? I'm creating a form(for visitors) that has options such as shape > size > color > availability/product which filter values for the last filter/select option (in this case availability). And is there any form field dependency implemented or is this just a matter of e.g. jquery events that trigger AJAX or visibility when field value is changed?
  23. Hi folks, Okay this is a bit of an odd one to explain so if you need to email please do at rich.g.cook(at)gmail.com and I'll happily pay a fee for any solutions if needed. I'm building a simple cart/checkout setup and on submission at the checkout the form action, on a static test, was submission.php and on this .php file it got the $_POST data from the form, parsed it using twig, and items and pushed it using swift mail to the seller and the buyer. This all works fine statically, but the issue is now it's on a CMS the $_POST data isn't getting saved across so upon submission all the fields (first name, address etc) are just returning blank. If I hard link the form submission to the templates folder to submission.php then it works but in the URL you have the weird .php whereas if I add it as a page and template in the CMS it drops the .php which is nicer but it doesn't seem to save any of the data this way. I know this is a bit confusing, but hopefully I've made some sense and you guys could help. Thanks, R
  24. I am trying to do the following: create a frontend form that generates a new page that has the fields from a template that a specific page uses. I send the page ID to the form and get the correct template and its fields from there. The presentation part of this form works, but as soon as it is trying to save, the $form variable does not contain the fields from the specified template so it saves a new page without any fields. Here's what I've got so far, hopefully anybody can tell me what I'm doing wrong (I've got most of this code from examples found on this forum): $page_id = htmlspecialchars($_POST['select_product']); // page ID $page = $pages->get($page_id); $template = $page->template; // this is the template where we will get the fields from // make a form $form = $modules->get('InputfieldForm'); $form->method = 'post'; $form->action = './'; $form->attr("id+name",'subscribe-form'); // add the page's fields to the form $fields = $page->fieldgroup; foreach($fields as $field) { $inputfield = $fields->get("$field->name")->getInputfield($page); $form->append($inputfield); } // add template name field to the form $field = $modules->get("InputfieldHidden"); $field->label = "Template"; $field->attr('id+name','template_name'); $field->required = 1; $field->value = $template; $form->append($field); // append the field // add a submit button to the form $submit = $modules->get('InputfieldSubmit'); $submit->name = 'save_new_aanvraag'; $submit->attr("value", "Go"); $form->append($submit); // process the form if it was submitted if($this->input->post->save_new_aanvraag) { // now we assume the form has been submitted. // tell the form to process input from the post vars. $form->processInput($this->input->post); // see if any errors occurred if( count( $form->getErrors() )) { // re-render the form, it will include the error messages echo $form->render(); } else { // successful form submission $p = new Page(); // create new page object $p->template = $input->post->template_name; // set template $p->parent = $pages->get('/aanvraag/'); // set the parent foreach($form as $field) { $p->set($field->name, $field->value); } $p->save(); //create the page echo "<p>Page saved.</p>"; } } else { echo $form->render(); }
  25. I am trying to do frontend page creation via AJAX but when the form is loaded into an element, things like CKeditor and proper image uploading do not work. It seems javascript should be re-initialized on the elements that got added to the DOM after the initial page has loaded, but I don't know how to do this (if that is even what should be done in the first place)? I got it working fine without AJAX, via a regular template. But when I move the code to a file that is called by AJAX, javascript breaks on the form hence things like CKeditor don't work. Here's what's in HEAD of the main template: <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title><?php echo $headline; ?></title> <link rel="stylesheet" href="<?php echo $config->urls->templates;?>css/foundation.css" /> <script src="<?php echo $config->urls->templates;?>js/vendor/modernizr.js"></script> <!-- Somatonic page edit script --> <script> <?php $jsConfig = $config->js(); $jsConfig['urls'] = array( 'root' => $config->urls->root, 'admin' => $config->urls->admin, 'modules' => $config->urls->modules, 'core' => $config->urls->core, 'files' => $config->urls->files, 'templates' => $config->urls->templates, 'adminTemplates' => $config->urls->adminTemplates, 'adminTemplates' => $config->urls->adminTemplates, ); ?> var config = <?php echo json_encode($jsConfig); ?>; </script> <?php //$config->styles->prepend($config->urls->adminTemplates . "styles/main.css?v=2"); //$config->styles->append($config->urls->adminTemplates . "styles/inputfields.css"); //$config->styles->append($config->urls->adminTemplates . "styles/ui.css?v=2"); $config->scripts->append($config->urls->JqueryUI . "JqueryUI.js"); $config->scripts->prepend($config->urls->JqueryCore . "JqueryCore.js"); $config->scripts->append($config->urls->adminTemplates . "scripts/inputfields.js"); foreach($config->styles->unique() as $file) echo "\n\t<link type='text/css' href='$file' rel='stylesheet' />"; foreach($config->scripts->unique() as $file) echo "\n\t<script type='text/javascript' src='$file'></script>"; ?> </head> It loads all the necessary script for frontend page creation. And here is the template that does the form processing: if ($command == "template_selection") { // Selected template ID $id = htmlspecialchars($_POST['template_id']); $page = $pages->get($id); $template = $page->template; foreach($template->fields as $field){ echo $field->label . ": "; //echo $field->type . "<br/>"; echo $page->get($field->name) . "<br/>"; } // make a form $form = $modules->get('InputfieldForm'); $form->method = 'post'; $form->action = './'; // add the page's fields to the form $form->add($page->getInputfields()); // add a submit button to the form $submit = $modules->get('InputfieldSubmit'); $submit->name = 'submit'; $form->add($submit); // process the form if it was submitted if($input->post->submit) { $form->processInput($input->post); $page->save(); echo '<p>saved</p>'; } // render the form output echo $form->render(); die; } This template works properly when not called by AJAX, but, again, when I call it with an AJAX request, the javascripts don't work. Is there any way I can make this work?
×
×
  • Create New...