vxda Posted October 22, 2013 Posted October 22, 2013 Hi guys, here is my code, im creating pages via form, but i want to show message when user allready submited his email. how can i achive this ? $out = ''; $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'subscribe-form'); $field = $modules->get("InputfieldEmail"); $field->label = "E-Mail"; $field->attr('id+name','email'); $field->required = 1; $form->append($field); // append the field $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Subscribe"); $submit->attr("id+name","submit"); $form->append($submit); if($input->post->submit) { $form->processInput($input->post); $email = $form->get("email"); if($email && (strpos($email->value,'@hotmail') !== FALSE)){ $email->error("Sorry we don't accept hotmail addresses for now."); } if($form->getErrors()) { $out .= $form->render(); }else{ $p = new Page(); // create new page object $p->template = 'newsletter'; // set template $p->parent = wire('pages')->get('/newsletter/'); // set the parent $p->name = $form->get("email")->value; // give it a name used in the url for the page $p->title = $form->get("email")->value; // set page title (not neccessary but recommended)\ $pageName = $p->name; $name = $pageName; $p->save(); $out .= "<p>You submission was completed! Thanks for your time."; } } else { // render out form without processing $out .= $form->render(); } echo $out; ?>
adrian Posted October 22, 2013 Posted October 22, 2013 All you need to do is use a selector to see if the email already exists. Do this inside the if($input->post->submit) { and if it exists, do an: $email->error("Sorry, this email address is already in our system"); The selector can use something like: $email_exists = $pages->find(selector); if(count($email_exists) > 0){ to determine is the email address is already in the system.
vxda Posted October 22, 2013 Author Posted October 22, 2013 Ty for reply Adrian still not working ;/thing is i made some pages one of is asd@asd.pl and when i run this : $email_exists = $pages->find('asd@asd.pl'); if(count($email_exists) > 0){ echo 'error'; } i get error : Fatal error: Exception: Unknown Selector operator: '' -- wasyour selector value properly escaped? (inD:\xampp\htdocs\projects\midven\wire\core\Selectors.php line 165)#0 D:\xampp\htdocs\projects\midven\wire\core\Selectors.php(190):Selectors->create('asd', '', '@asd.pl')#1 D:\xampp\htdocs\projects\midven\wire\core\Selectors.php(63):Selectors->extractString('asd@asd.pl')#2 D:\xampp\htdocs\projects\midven\wire\core\Pages.php(143):Selectors->__construct('asd@asd.pl')#3 [internal function]: Pages->___find('asd@asd.pl')#4 D:\xampp\htdocs\projects\midven\wire\core\Wire.php(271):call_user_func_array(Array, Array)#5 D:\xampp\htdocs\projects\midven\wire\core\Wire.php(229):Wire->runHooks('find', Array)#6D:\xampp\htdocs\projects\midven\site\templates\global\newsletter.html(46):Wire->__call('find', Array)#7D:\xampp\htdocs\projects\midven\site\templates\global\newsletter.html(46):Pages->find('asd@asd.pl')#8 D:\xampp\htdocs\projects\midven\site\templates\home.php(8):include('D:\xampp\htdocs...')#9 D:\xampp\htdocs\p in D:\xampp\htdocs\projects\midven\index.php on line 214
Wanze Posted October 22, 2013 Posted October 22, 2013 you need so specify also what field you want to search in your selector. Also there exists $pages->count() which is faster than a find, if you don't need any values: if ($pages->count('title=asd@asd.pl')) { echo 'error'; } In your code, I noticed that you set the email addy also as page name, but for example an '@' is not supported there. You can omit setting the name and Pw will generate it for you based on the title. But if you set it yourself, then use $sanitizer->pageName(): $email = $form->get('email')->value; $p->title = $email; $p->name = $sanitizer->pageName($email); // Or delete this line... $pageName = $p->name; // What are you doing here? $name = $pageName; // And here? $p->save(); Cheers 2
adrian Posted October 22, 2013 Posted October 22, 2013 That's not a valid selector. You could do: $pages->find("title=asd@asd.pl"); EDIT: Wanze beat me 2
vxda Posted October 22, 2013 Author Posted October 22, 2013 Thank you guys for your time, its finaly working. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now