-
Posts
1,147 -
Joined
-
Last visited
-
Days Won
4
Everything posted by onjegolders
-
I think I have it (largely thanks to you Diogo) <?php if($input->post->submit) { foreach ($input->post->delete as $s) { $dp = $pages->find("template=student, name=$s"); $du = $users->find("name=$s"); if($dp){ foreach ($dp as $p) { $pages->delete($p); } echo $p->name . " has been deleted!"; }else{ echo "I didn't find" . $p->name; } if($du){ foreach ($du as $u) { $users->delete($u); } echo $u->name . " has been deleted!"; }else{ echo "I didn't find" . $u->name; } } } ?> <form action="" method="post"> <ul> <?php foreach ($pages->get("template=students")->children() as $student) { ?> <li> <?php echo $student->name; ?> <input type="checkbox" name="delete[]" value="<?php echo $student->name; ?>"> </li> <?php } ?> <input type="submit" value="Delete selected users" name="submit"> </ul> </form> If anyone has any improvements, or friendly advice, it's always much appreciated. I can get lost for whole days trying to set these sort of things up and people like Diogo (and others) are vital to keep me rolling with PW. I hope maybe in a year or so, my PHP and PW skills will be such that I'll be able to return the favour. I'm aware that it's pretty one-way at times!
-
Thanks Diogo, you're always so helpful and it's much appreciated. Think I was trying to solve this problem at the end of a long day and you're right it's a bit all over the place. My idea was just to have a checkbox next to the name of every student and then our editor could select say 5 of them and hit delete at the bottom and those users would be deleted. Thanks for your code and suggestions, if it doesn't work, is there a simpler, different approach, I was thinking maybe have a form where the editor could add users to a new array which would then get deleted but my brain's a bit fried at the moment!
-
Hi again guys, as part of my plan to offer a fully-fledged front-end student management system for my site, I'm trying to add a page where there is a list of all students and a checkbox next to each name. Whichever student has a checkbox next to their name gets deleted upon form submit. Have tried the following but think I have lost my way! <?php if($input->post->submit) { $students = $pages->get("template=students")->children(); foreach ($input->post->$student->name as $s) { if (isset($s)) { $deletable = $users->get($student->name); $deletable->delete(); echo $deletable->name . " has been deleted!"; } } } ?> <form action="" method="post"> <ul> <?php foreach ($students as $student) { ?> <li> <?php echo $student->name; ?> <input type="checkbox" name="<?php echo $student->name; ?>"> </li> <?php } ?> <input type="submit" value="Delete selected users" name="submit"> </ul> </form> Am I missing something simple here? For those who are stuck doing similar things, I have managed to get the adding and modifying students front-end bit pretty sorted I think so more than happy to lend a hand!
-
Sort Images via API (outside PW admin)
onjegolders replied to ryanscherler's topic in General Support
Bumping this as I'm trying to figure out how to replace an image with an uploaded one. The only difference from the above is that I'm not using an array for image. Like Soma I figured that for my new uploaded image file to overwrite the existing one I would have to delete it before adding the new one. I have tried remove, unset, delete but can't seem to figure out how to do this? If it's impossible I could always use an array of images and call out the most recent I suppose. -
You're right Martijn, the array() needs adding, thanks.
-
Thanks Yellow, are you aware of any PW snippets for SublimeText2? I may have to look into that. I do have basic HTML and CSS snippets to get me up and running was just wondering if there were any specific tips directly realting to Processwire and maybe even the admin side.
-
Thanks Ryan will double check all is normal and then contact GoDaddy
-
Best way to use page fields in a selector tag
onjegolders replied to onjegolders's topic in General Support
Great, thanks Ryan will check that out! -
Sorry Apeisa I just meant should it not be automatically selected as "on" for all newly created text fields rather than having to manually turn it on?
-
Was just wondering what time-saving tips you guys have from one project to the next. Are there things you carry over? Every time you add a contact form do you code it from scratch? Or do you go to another local project and copy and paste code over? I'm just conscious that though the main reason I love PW is that I code it all myself, line by line, it also means I probably end up spending too much time in the nitty gritty. So do you have any time saving tips? Am also interested in your workflows within the admin section (think I've asked this before). Is there anything in particular you've learned that helps you get your PW projects up and running faster? Cheers!
-
OK thanks, anyway of putting it on as standard?
-
Thanks Ryan, is there any reason why it's not on by default? Should I generally leave it on for all text fields?
-
Thanks both of you, I've got it working as expected. I've also got my extended user system working quite nicely with adding/editing students/users front-end if anyone else gets stuck and needs a pointer.
-
Thanks Diogo!
-
Think I've got it, for my select, it should read <select multiple name="subject[]"> The square brackets create an array. Is that the best way?
-
Thanks Diogo, any idea on how to combine that with $input->post->type? It would be coming from a front-end form, probably as the output of a multi select or checkbox. At the moment I have this, which returns the first selected subject but cannot get more than 1. I'm imagining I have to input it somehow as an array? <?php // user is authenticated and may change their password if($input->post->submit_pass) { if($input->post->pass !== $input->post->pass_confirm) { echo "<h2>Passwords do not match!</h2>"; } else if(strlen($input->post->pass) < 6) { // if you want to enforce a minimum password length (recommended) echo "<h2>Your password is too short. Must be 6 characters or more.</h2>"; } else { $student_page = new Page(); $student_page->of(false); $student_page->template = "student"; $student_page->parent = $pages->get("/students/"); $student_page->title = $input->post->first_name . " " . $input->post->last_name; $student_page->set("first_name", $input->post->first_name); $student_page->set("last_name", $input->post->last_name); $student_page->set("email", $input->post->email); $student_page->set("skype_name", $input->post->skype_name); $student_page->set("subject", $input->post->subject); $student_page->save(); $student_page->of(true); echo "<h5>Student has been added</h5>"; } } ?> <form action="" id="add_user" method="post"> <label for="username">Username</label> <input type="text" name="username"> <label for="first_name">First Name</label> <input type="text" name="first_name"> <label for="last_name">Last Name</label> <input type="text" name="last_name"> <label for="email">Email address</label> <input type="text" name="email"> <label for="skype_name">Skype name</label> <input type="text" name="skype_name"> <label for="pass">New password</label> <input type="password" name="pass"> <label for="pass_confirm">Confirm password</label> <input type="password" name="pass_confirm"> <label for="subject">Subject</label> <select multiple name="subject"> <?php foreach ($pages->get("template=subjects")->children() as $subject) { ?> <option name="subject" value="<?php echo $subject->id; ?>"><?php echo $subject->title; ?> <?php } ?> </select> <input type="submit" name="submit_pass"> </form>
-
Thanks Wanze! This looks great, will check it out and let you know
-
Thanks again, any ideas how to update a "page" field via the API? I can use either a multi select or a checkbox in the form but not too sure how to send that to the newly created page. My example is a new student who needs to be linked to one or more subjects (subjects are pages)
-
Apologies, on my 10th google I found this link: I find it quite hard to get my search right from within the forum, maybe it's easier through Google. Thanks Reno, must've posted at the same time!
-
Sorry, but can find no reference to be able to create pages using the API but am sure it's possible. Is there a reference anywhere? At present, I'm using guesswork.. $new_page = new Page(); How do you set the name, template and parent? Any nod in the right direction would be much appreciated.
-
Thanks Teppo, sounds a bit beyond me at the moment but may put it down as something to learn one day!
-
Investor area, best way to layout permission-only pages
onjegolders replied to onjegolders's topic in General Support
Scrap that, think I have sorted it, I've reallowed urlSegments for the "student" profile and it seems to be working, thanks.