Jump to content

sam13579

Members
  • Posts

    26
  • Joined

  • Last visited

Posts posted by sam13579

  1. I want to create a form field with which I can upload the image/file. But it is not working. Is there anyone to guide?
     

    $saved="";    
    echo $_FILES['pp']['name'];
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
    $upload_path = $config->paths->assets . "files/.tmp_uploads/";
            print_r($tempdir);
    
    
        $doc = new WireUpload('pp');
        $doc->setMaxFiles(1);
        $doc->setOverwrite(true);
        $doc->setDestinationPath($upload_path);
        $doc->setValidExtensions(array('jpg', 'jpeg', 'png', 'pdf'));
        $files = $doc->execute();
    print_r($files);
     $uploadpage = new Page();
            $uploadpage->template = "progr";
            $uploadpage->parent = $pages->get("/add-progr/");
            // add title/name and make it unique with time and uniqid
            $uploadpage->title = "Some Text";
    
            $uploadpage->save();
            foreach($files as $file){
                    $uploadpage->programme_photo=$uploadPath.$file;
                print_r($file);
            };
            $uploadpage->save();
            $saved="Saved";

     

  2. On 11/3/2011 at 5:04 PM, Soma said:

    You can get user created and modified for a page with

     

    <?php
    $page->createdUser->name;
    $page->modifiedUser->name;
    
     

    $page would be $child in your code

    Is there a documentations for all these things? 

  3. This is the code

        $thanks = "";
        $tempDir = $config->paths->assets . "files/applications/";
        if ($input->post('title')) {
            print_r($input->get('doc'));
            $p = new Page();
            $p->template = 'Application'; //or whatever your template is called
            $p->parent = wire('pages')->get('/applications/'); //or whatever the parent page is called        
            $p->application_title = $input->post->text('title');
            $p->application_first_name = $input->post->text('fname');
            $p->application_middle_name = $input->post->text('mname');
            $p->application_last_name = $input->post->text('lname');
            $p->application_position = $input->post->text('position');
                     echo "<script>window.alert('".$input->post('doc')."');</script>";
            $p->application_email = $input->post->email('email');    
            $p->application_reference_no = $input->post->text('ref_no');    
            $p->application_telephone_no= $input->post->text('tel_no');
            $p->application_date= $input->post->text('date');
            $p->save();
            
      $files = explode("|",$input->get('doc')->value);
            foreach($files as $file){
                if($file && file_exists($tempDir . $file)){
                    $p->application_document->add($tempDir . $file);
                    print_r($p);
                }
            }
            $p->save();   
        }
    ?>

     

    And the html part is :
    <form action='' method='post' enctype="multipart/form-data">
              <div class=''>
              <label for='title'>Title</label>
              <select name='title' id='title'>
               <option value='Mr.'>Mr.</option>
        <option value='Ms.'>Ms.</option>
       </select>
              </div>
              <div class=''>
              <label for='fname'>First Name</label>
              <input id='fname' type='text' name='fname' />
              </div>
              <div class=''>
              <label for='mname'>Middle Name</label>
              <input id='mname' type='text' name='mname' />
              </div>
              <div class=''>
              <label for='lname'>Last Name</label>
              <input id='lname' type='text' name='lname' />
              </div>
              
              <div class=''>
              <label for='position'>Position</label>
              <input id='position' type='text' name='position' />
              </div>
              <div class=''>
              <label for='ref_no'>Reference No.</label>
              <input id='ref_no' type='text' name='ref_no' />
              </div>
              <div class=''>
              <label for='email'>E-mail</label>
              <input id='email' type='email' name='email' />
              </div>
              
              <div class=''>
              <label for='tel_no'>Telephone No.</label>
              <input id='tel_no' type='text' name='tel_no' />
              </div>
              <div class=''>
              <label for='document'>Document(PDF)</label>
              <input id='document' type='file' name='doc' />
              </div>
              <div class=''>
              <label for='date'>Date</label>
              <input id='date' type='date' name='date' />
              </div>
              <button type='submit' class="btn btn-bronze-outline rounded-pill">Apply Now</button>
              </form>

    Evrything is stored except for the file. What might be wrong here?

  4. 1 hour ago, pwired said:

    I was addressing your first question

    This is a different question

    Have you read the Processwire Documentation ?
    Your answers are here:

    https://processwire.com/docs/start/variables/templates/

    ---------------------------------------------------------------------
    Creating a new template with api

    <?php namespace ProcessWire;
    $fieldgroup = new Fieldgroup();
    $fieldgroup->name = "something";
    $fieldgroup->add("title"); // add some fields
    $fieldgroup->add("body");
    $fieldgroup->add("summary");
    $fieldgroup->save();
    
    $template = new Template();
    $template->name = "something"; // must be same name as the fieldgroup
    $template->fieldgroup = $fieldgroup;
    $template->save();

    ---------------------------------------------------------------------
    Adding fields to a template with api

    <?php namespace ProcessWire;
    $template = $templates->get("some_template");
    $template->fields->add("body"); // add some fields
    $template->fields->add("summary");
    $template->fields->add("images");
    $template->fields->save(); 

    ---------------------------------------------------------------------

    Forum
    https://processwire.com/talk/topic/4921-how-to-create-template-file-using-api-under-a-module/
    https://processwire.com/talk/topic/352-creating-pages-via-api/

    Examples
    https://processwire-recipes.com/recipes/add-fields-to-template/

    Beginner mistakes
    https://processwire.com/talk/topic/19415-trying-to-create-field-using-api/

     

     

     

     

     

    That saved my day. Thanks.

  5. 8 hours ago, pwired said:

    Have you seen the processwire documentation ?

    https://processwire.com/api/ref/field/

    1) Setup a field of type textarea
    2) Echo or include the textarea field where you want it

    echo $Yourpage->yourfield;
    include $Yourpage->yourfield;

    I was looking for a way to make template with fields programatically. But I think this is not happening. What you are suggesting is adding fields that are already made inside database. But thanks.

  6. On 3/7/2017 at 11:50 PM, fbg13 said:

    @modifiedcontent Say you have the following form 

    <form method="post">
      <input type="text" name="name">
      <input type="textarea" name="message">
      <input type="submit" name="submit">
    </form>

    You can save it to a page like this

    <?php
    
    if($input->post->submit) {
    	$p = new Page();
    	$p->template = "template_to_save_form";
    	$p->parent = $pages->get("/parent-page/");
    	$p->title = $input->post->name . " - " . date("Y-m-d");
    	$p->submitted_by = $input->post->name;
    	$p->message = $input->post->message;
    	$p->save();
    }

    You'll have to create the template, its fields and the parent page first.

    Also before saving the page make sure to validate/sanitize the input.

    <?php
    $p->submitted_by = $sanitizer->text($input->post->name);
    // instead of just 
    $p->submitted_by = $input->post->name;

    https://processwire.com/api/ref/sanitizer/

    This means I have to save form data as a page?

  7. Like most of the people I started with WordPress. But for some reason WordPress was too hard for me. Then I found Processwire and it seems very easy for me. But still I have some problems with many small things. I think programming is mostly about input, output and how do we process things. But I am facing many holes now and then in the tutorials.  I am going to give some specification:

    1. I found a tut where form submission was demonstrated . There I found that there is a special way to get the form input. It was with processInput() method. But that method is not working correctly.

    2. I found no specification about how I save a form data into database .

    3. I have to use  $this->modules->get() , $modules->get()

    I think I will face many more problems later. What is wrong with me? Am I too beginner for this? Or am I missing something?

  8. 8 hours ago, wbmnfktr said:

    Maybe my day was already way too long and I don't understand your question and needs here... but... what do you want to accomplish with this and where?

    In the frontend? In the backend? Within a page, a form, or... 

    Your question and code sample somehow don't match for me.

    I want to create this same thing where I can add attributes to the program like the program I gave. I want to do this for frontend text input field.

  9. This thing might sound weird , but I would like to make a similar class that can make HTML element like this:

    $inputfield = $modules->get('InputfieldText');
    $inputfield->label = 'Your Name';
    $inputfield->attr('name', 'your_name');
    $inputfield->attr('value', 'Roderigo');
    // Add to a $form (InputfieldForm or InputfieldWrapper)
    $form->add($inputfield); 

    How can I make a class so that I can make simple text input fields with the code. I am not very good at OOP. It would be a great thing to learn.

     

  10. 7 hours ago, Ivan Gretsky said:

    Welcome to the forums, @Shohan Arafat!

    If you want it in admin it must be a custom process module. You can learn how to make one here (for example).

    But I am not sure I really understood your needs. This is your 1st post, and it might be you meant something very different. Please explain your needs better if my link above is too much or completely irrelevant.

    This is the exact thing that I was wanting. Thanks for the share. ?

    • Like 1
×
×
  • Create New...